physics objects falling through each other

I’m having an issue with physics bodies falling through each other. I’m using a device tilt code that I found to move an object named inf around. When inf strikes either wall object the inf body looks like it sticks into the wall, and if you keep tilting the device it eventually falls through.

Is there any solution to this or is this an issue with the box 2d physics?

[code]

display.setStatusBar( display.HiddenStatusBar )

local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0)

physics.setDrawMode( “hybrid” )

local inf = display.newCircle( 320, 480, 25 )
physics.addBody( inf, { density = 1, bounce = 3, radius = 30 } )

local wall = display.newRect( 200, 200, 200, 50 )
physics.addBody( wall, “static”, { w = 200, h = 50, density = 3, bounce = 1 } )

local walltwo = display.newRect( 200, 0, 50, 200 )
physics.addBody( walltwo, “static”, { w = 50, h = 200, density = 3, bounce = 1 } )

local motionx = 0
local motiony = 0

local function onAccelerate(event)

motionx = 45 * event.xGravity
motiony = 45 * event.yGravity

end

Runtime:addEventListener( “accelerometer”, onAccelerate )

local function moveinf(event)

inf.x = inf.x + motionx
inf.y = inf.y - motiony

if inf.x < 0 then

inf.x = 0

elseif inf.x > 640 then

inf.x = 640

end

if inf.y < 0 then

inf.y = 0

elseif inf.y > 960 then

inf.y = 960

end

end

Runtime:addEventListener( “enterFrame”, moveinf )

[/code] [import]uid: 10903 topic_id: 13511 reply_id: 313511[/import]

Have you seen this, just posted:
http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/

The solution to your problem might be somewhere in there. Without tweaking different settings/trying different things, it’s really hard to tell what exactly is the source of the problem.

You should try playing with the bounce property, as well as the friction of the walls. Additionally, if all else fails, you might try applying a small amount of force whenever a collision occurs (in the opposite direction, of course).

Have a look at the link though, and once you’ve tried everything, reply back and let me know if it’s still not working. [import]uid: 52430 topic_id: 13511 reply_id: 49595[/import]

Just saw your serendipitous post after I posted the question.

I’ve been messing with the values you suggested to try and added some things, but still having issues. I had assumed that the collision listener would solve the issue, but that doesn’t seem to have much of an effect, I’d guess I’m doing it incorrectly or unsure of how to add it. Modified code below:

[code]
display.setStatusBar( display.HiddenStatusBar )

local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0)

physics.setDrawMode( “hybrid” )
physics.setScale( 60 )
physics.setVelocityIterations( 80 )
physics.setPositionIterations( 80 )

local inf = display.newCircle( 320, 480, 25 )
physics.addBody( inf, { density = 20, bounce = 3, radius = 30, friction = 0 } )

local wall = display.newRect( 200, 200, 200, 50 )
physics.addBody( wall, “static”, { w = 200, h = 50, density = 20, bounce = 3, friction = 0 } )

local walltwo = display.newRect( 200, -100, 50, 400 )
physics.addBody( walltwo, “static”, { w = 50, h = 200, density = 20, bounce = 3, friction = 0 } )

local motionx = 0
local motiony = 0

local vx, vy
local tx = 320
local ty = 480

local function onAccelerate(event)

motionx = 45 * event.xGravity
motiony = 45 * event.yGravity

end

Runtime:addEventListener( “accelerometer”, onAccelerate )

local function moveinf(event)

inf.x = inf.x + motionx
inf.y = inf.y - motiony

if inf.x < 0 then

inf.x = 0

elseif inf.x > 640 then

inf.x = 640

end

if inf.y < 0 then

inf.y = 0

elseif inf.y > 960 then

inf.y = 960

end

end

Runtime:addEventListener( “enterFrame”, moveinf )

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

print(“check”)
vx, vy = self:getLinearVelocity()
self:setLinearVelocity( -vx, -vy )

end
end

inf.collision = onLocalCollision
inf:addEventListener( “collision”, inf )

[/code] [import]uid: 10903 topic_id: 13511 reply_id: 49597[/import]

I would suggest you try using addForce() instead, just to see if that helps anything… [import]uid: 52430 topic_id: 13511 reply_id: 49658[/import]