I’m starting to work with physics for the first time and have some odd behaviors. I started from the DragPlatforms sample, at least as far as the properties of the objects. But I removed the changing of the bodyType on touch, since I am moving my object via D-pad like controls, from Peach’s tutorial on that.
I start with a couple ground objects which are 60x60 images. I have a blocky ‘car’, a 55x55 image, which starts sitting on one of the ground blocks. I then click on the d-pad controls to slowly move the car over the edge of the ground. When more than half of the car is hanging off the edge, it starts to tip off the edge as you’d expect. But as it begins to fall off the edge it rotates oddly, as if there was something holding it at the upper left corner(when it goes off the right edge of the ground), and then begins to pass through the ground block.
It behaves even stranger when going off the left edge of the ground. Then it actually rotates up and to the left.
I’ve searched the forums, re-read the physics docs, looked at the ‘Solutions to Common Physics Problems’ post; experimented with density, physics.setScale, physics.setPositionIterations, physics.setVelocityIterations(); and adding all the objects to a displayGroup. Nothing has had any effect. I put the physics Draw Mode to debug and didn’t see anything unusual, just the blocky squares.
I’d appreciate any suggestions. Thanks.
Here’s the relevant code:
[lua]local ground = display.newImage( “rockGrid.png” )
ground.x = 60; ground.y = 200
local ground2 = display.newImage( “rockGrid.png” )
ground2.x = 120; ground2.y = 200
physics.addBody( ground, “static”, { density=3.0, friction=0.5, bounce=0.2 } )
physics.addBody( ground2, “static”, { density=3.0, friction=0.5, bounce=0.2 } )
local car= display.newImage( “car55.png” )
car(display.TopLeftReferencePoint)
car.x = 30;
car.y = ground.y - car.height;
physics.addBody( car, { density=1.5, friction=0.5, bounce=0.2 } )
group = display.newGroup()
group:insert( ground )
group:insert( ground2 )
group:insert( car )[/lua] [import]uid: 82378 topic_id: 18544 reply_id: 318544[/import]
[import]uid: 52491 topic_id: 18544 reply_id: 71232[/import]