Newby question about physics

Hi everyone, I am new to Corona and I’ve started developing my first game. The main premise is like the classic wooden Labyrinth game where you maneuver a ball through a maze. I created my images in Photoshop and saved them as png files. I’ve put the screen together, and added the walls and physics. I wasn’t sure how I’d test the accelerometer functionality so for now I was going to just let the ball fall into the maze from the top of the screen. The issue I have is the ball gets stuck. However it isn’t actually touching anything! It falls into an opening with room to spare on both sides and gets stuck. I added the functionality from the Drag Platforms sample so I can drag the ball to other locations on the screen to see if it has the same problem. It seems to occur everwhere on my screen. I also commented out the line event.target.bodyType = “kinematic” (from the sample code I borrowed) to force gravity to stay on. The ball goes crazy jumping all over the screen! What am I missing?

Thank you again for your time.

Sincerely,
Marc [import]uid: 10413 topic_id: 3597 reply_id: 303597[/import]

Wow, I’ve waited a few days but no answers? Come on Ansca community, there are so many knowledgable people here, nobody has had this happen before? To clarify, I’ve got a ball trying to pass through a maze but gets stuck against nothing. It goes part of the way into the maze and stops. It’s as though it has invisible borders or trim of some kind. I created the images as png files in Photoshop so they shouldn’t have invisible borders right? Anyone with any insight is much appreciated.

Thanks,
Marc [import]uid: 10413 topic_id: 3597 reply_id: 11101[/import]

we can’t tell what’s wrong if you don’t share your code!
[import]uid: 6645 topic_id: 3597 reply_id: 11112[/import]

Thanks, ok here is the code. I hadn’t posted it only because it is extremely basic.

Since I am still learning this is all in main.lua. Eventually I’ll break it out. I was just trying to figure out how to get it working.
On a side note, this game will ultimately have more than one level. Is the suggestion to break out the assets for each level as its own lua file? i.e. level1.lua, level2.lua, etc.

Contents of main.lua:

– Activate physics engine
local physics = require(“physics”)
physics.start()

display.setStatusBar( display.HiddenStatusBar )
local bkg = display.newImage( “Background1_1.png” )
bkg.x = 160; bkg.y = 260

local leftWall = display.newImage( “VerticalBoundary_1.png”)
leftWall.x = 10; leftWall.y = 260

physics.addBody( leftWall, “static”, { friction=0.5, bounce=0.3 } )

local rightWall = display.newImage( “VerticalBoundary_1.png”)
rightWall.x = 312; rightWall.y = 260

physics.addBody( rightWall, “static”, { friction=0.5, bounce=0.3 } )

local bottomWall = display.newImage( “HorizontalBoundary_1.png”)
bottomWall.x = 160; bottomWall.y = 474

physics.addBody( bottomWall, “static”, { friction=0.5, bounce=0.3 } )

local topWall = display.newImage( “HorizontalBoundary_1.png”)
topWall.x = 160; topWall.y = 29

physics.addBody( topWall, “static”, { friction=0.5, bounce=0.3 } )

local curve1 = display.newImage( “Curve1_1.png”)
curve1.x = 105; curve1.y = 85

physics.addBody( curve1, “static”, { friction=0.5, bounce=0.3 } )

local curve2 = display.newImage( “Curve2_1.png”)
curve2.x = 70; curve2.y = 125
curve2:scale(1, 1.1)

physics.addBody( curve2, “static”, { friction=0.5, bounce=0.3 } )

local curve3 = display.newImage( “Curve3_1.png”)
curve3.x = 230; curve3.y = 88

physics.addBody( curve3, “static”, { friction=0.5, bounce=0.3 } )

local curve4 = display.newImage( “Curve4_1.png”)
curve4.x = 273; curve4.y = 90

physics.addBody( curve4, “static”, { friction=0.5, bounce=0.3 } )

local curve5 = display.newImage( “Curve5_1.png”)
curve5.x = 210; curve5.y = 190

physics.addBody( curve5, “static”, { friction=0.5, bounce=0.3 } )

local curve6 = display.newImage( “Curve6_1.png”)
curve6.x = 205; curve6.y = 213

physics.addBody( curve6, “static”, { friction=0.5, bounce=0.3 } )

local curve7 = display.newImage( “Curve7_1.png”)
curve7.x = 130; curve7.y = 230

physics.addBody( curve7, “static”, { friction=0.5, bounce=0.3 } )

local curve8 = display.newImage( “Curve8_1.png”)
curve8.x = 100; curve8.y = 275
curve8:scale(.9, .9)
physics.addBody( curve8, “static”, { friction=0.5, bounce=0.3 } )
local curve10 = display.newImage( “Curve10_1.png”)
curve10.x = 240; curve10.y = 280

physics.addBody( curve10, “static”, { friction=0.5, bounce=0.3 } )

local curve11 = display.newImage( “Curve11_1.png”)
curve11.x = 259; curve11.y = 330

physics.addBody( curve11, “static”, { friction=0.5, bounce=0.3 } )

local curve12 = display.newImage( “Curve12_1.png”)
curve12.x = 164; curve12.y = 330
curve12:scale(.7, .8)
physics.addBody( curve12, “static”, { friction=0.5, bounce=0.3 } )

local curve13 = display.newImage( “Curve13_1.png”)
curve13.x = 32; curve13.y = 370
curve13:scale(.8, .8)
physics.addBody( curve13, “static”, { friction=0.5, bounce=0.3 } )

local curve14 = display.newImage( “Curve14_1.png”)
curve14.x = 53; curve14.y = 423

physics.addBody( curve14, “static”, { friction=0.5, bounce=0.3 } )

local curve15 = display.newImage( “Curve15_1.png”)
curve15.x = 53; curve15.y = 420
curve15:scale(.8, .8)
physics.addBody( curve15, “static”, { friction=0.5, bounce=0.3 } )

local curve16 = display.newImage( “Curve16_1.png”)
curve16.x = 165; curve16.y = 415
curve16:scale(.9, .9)
physics.addBody( curve16, “static”, { friction=0.5, bounce=0.3 } )

local curve17 = display.newImage( “Curve17_1.png”)
curve17.x = 150; curve17.y = 435
curve17:scale(.8, .8)
physics.addBody( curve17, “static”, { friction=0.5, bounce=0.3 } )

local curve19 = display.newImage( “Curve19_1.png”)
curve19.x = 215; curve19.y = 380
curve19:scale(.8, .8)
physics.addBody( curve19, “static”, { friction=0.5, bounce=0.3 } )

local curve20 = display.newImage( “Curve20_1.png”)
curve20.x = 275; curve20.y = 400
curve20:scale(.8, .8)
physics.addBody( curve20, “static”, { friction=0.5, bounce=0.3 } )
local startHole = display.newImage( “StartHole_1.png”)
startHole.x = 176; startHole.y = 50

physics.addBody( startHole, “static”, { friction=0.5, bounce=0.0 } )

local finishHole = display.newImage( “FinishHole_1.png”)
finishHole.x = 155; finishHole.y = 425

physics.addBody( finishHole, “static”, { friction=0.5, bounce=0.0 } )

local warpHole1 = display.newImage( “WarpHole_1.png”)
warpHole1.x = 30; warpHole1.y = 200

physics.addBody( warpHole1, “static”, { friction=0.5, bounce=0.0 } )

local warpHole2 = display.newImage( “WarpHole_1.png”)
warpHole2.x = 285; warpHole2.y = 410

physics.addBody( warpHole2, “static”, { friction=0.5, bounce=0.0 } )
local bumper1 = display.newImage( “bumper.png”)
bumper1.x = 30; bumper1.y = 50

physics.addBody( bumper1, “static”, { friction=0.5, bounce=0.8 } )

local bumper2 = display.newImage( “bumper.png”)
bumper2.x = 130; bumper2.y = 225

physics.addBody( bumper2, “static”, { friction=0.5, bounce=0.8 } )

local bumper3 = display.newImage( “bumper.png”)
bumper3.x = 290; bumper3.y = 180

physics.addBody( bumper3, “static”, { friction=0.5, bounce=0.8 } )

local bumper4 = display.newImage( “bumper.png”)
bumper4.x = 165; bumper4.y = 320

physics.addBody( bumper4, “static”, { friction=0.5, bounce=0.8 } )

local bumper5 = display.newImage( “bumper.png”)
bumper5.x = 290; bumper5.y = 362

physics.addBody( bumper5, “static”, { friction=0.5, bounce=0.8 } )

local bumper6 = display.newImage( “bumper.png”)
bumper6.x = 65; bumper6.y = 410

physics.addBody( bumper6, “static”, { friction=0.5, bounce=0.8 } )

local hole1 = display.newImage( “hole_1.png”)
hole1.x = 60; hole1.y = 155

local hole2 = display.newImage( “hole_1.png”)
hole2.x = 290; hole2.y = 85

local hole3 = display.newImage( “hole_1.png”)
hole3.x = 200; hole3.y = 240

local hole4 = display.newImage( “hole_1.png”)
hole4.x = 240; hole4.y = 270

local hole5 = display.newImage( “hole_1.png”)
hole5.x = 80; hole5.y = 270

local hole6 = display.newImage( “hole_1.png”)
hole6.x = 30; hole6.y = 355

local hole7 = display.newImage( “hole_1.png”)
hole7.x = 30; hole7.y = 440

local hole8 = display.newImage( “hole_1.png”)
hole8.x = 210; hole8.y = 370

local hole9 = display.newImage( “hole_1.png”)
hole9.x = 230; hole9.y = 450
local ball = display.newImage( “steelball2.png” )
ball.x = 170; ball.y = 60
ball:scale(.3, .3)
physics.addBody( ball, { density=3.0, friction=0.5, bounce=0.3 } )
I can send someone the images if needed.

Thank you very much to the community for the help.

Marc [import]uid: 10413 topic_id: 3597 reply_id: 11172[/import]

Ok so I tried a few other things to figure this out. First I removed all of objects with physics on them and of course the ball falls. The second thing I did that shed light on what is happening was putting physics in debug mode: physics.setDrawMode( “debug” ).
That showed me that all of the objects seem to be represented as large blocks. Many of my images were curves so I assumed they would be curves, not blocks. Of course the blocks overlap so the ball will never go anywhere. I’m not sure how to create my images to be the shapes they are intended. Also the collision blocks are much larger than the objects themselves. I’m not sure why that is the case. I think it must have something to do with the way I saved the images. Hopefully that sheds more light on my issue.

Thank you again for your time.

Marc [import]uid: 10413 topic_id: 3597 reply_id: 11179[/import]

hi,

you need to find some way to get coordinates for your curves as a group of convex polygons (you cant have concave polygons)
(see my post here about that: http://developer.anscamobile.com/forum/2010/11/03/physics-complex-polygon-tool)

you’ll need to look around for a tool that suits you, or you can always revert to graph paper!

also when you post code please wrap it in <lua> </lua> so it is more readable like this
[lua]-- Activate physics engine
local physics = require(“physics”)
physics.start()[/lua]

with that many graphics though you’d be best putting a zip up on sendspace.com or something

j [import]uid: 6645 topic_id: 3597 reply_id: 11182[/import]

Thanks jmp909. I read the same thing in the API resources.

http://developer.anscamobile.com/content/game-edition-physics-bodies

Specifically:

Also note that this default constructor assumes that your physics object has the same rectangular boundaries as your display object. This is very convenient in many cases, but in other cases may not be what you want. For example, a vector line drawn diagonally using display.newLine() is actually rendered as a rectangular object, since it creates a rectangular area of OpenGL texture (which would be mostly transparent, in this case).

I will look at the sample you provided. My shapes are a series of curves so I’d have to perform a function like this on 20 or so objects. I wonder if that will degrade performance?

Thanks again for the great insight!

Marc [import]uid: 10413 topic_id: 3597 reply_id: 11186[/import]