Accelerometer and Physics Problem

I am having a problem with physics collisions using accelerometer and physics. I have a round object that i am moving with accelerometer using the objects x,y coords. When the object hits my test wall it goes half way through and if i keep tilting that way it will keep going through. Ive tried setting physics iterations and isbullet but those did not work. This device is set to landscape right, what is why i switched the xGravity and yGravity on the accelerometer function. Below is some plug and play code, thanks in advance for your help.

[lua]display.setStatusBar(display.HiddenStatusBar)

local physics = require (“physics”)
physics.start()
physics.setGravity (0, 0)
physics.setDrawMode (“hybrid”)
_w = display.contentWidth
_h = display.contentHeight

local Scene = display.newGroup ()
local starCir = display.newCircle(Scene, 0, 0, 16 )
starCir.x = 460; starCir.y = 30;
physics.addBody( starCir, “dynamic”, { radius = 16})

local accX = 0
local accY = 0

local testWall = display.newRect (Scene, 0, 0, 480, 20)
testWall.x = _w/2; testWall.y = 310;
physics.addBody ( testWall, “static”)

local onAccelerate = function (event)
accX = 20 * event.yGravity
accY = 20 * event.xGravity

end

local moveBall = function ( event )
starCir.x = starCir.x - accX
starCir.y = starCir.y - accY
end

Runtime:addEventListener (“enterFrame”, moveBall)
Runtime:addEventListener (“accelerometer”, onAccelerate)[/lua] [import]uid: 126161 topic_id: 23184 reply_id: 323184[/import]

Make your ball a bullet.

starCir.isBullet = true  

Also you’re not suppose to move dynamic physics object by changing the objects x,y. The best way to move dynamic physics objects is by using force, impulse or setting the velocity.

Instead of using dynamic you could always try using the kinematic.

starCir.bodyType = "kinematic"  

[import]uid: 38820 topic_id: 23184 reply_id: 92736[/import]

I already tried isBullet with kinematic, dynamic, and static props, like i said in the first post. dynamic is the only one that will actually hit the wall, all the others go strait thru, I understand it is because of moving the circle by x,y. since it works so well i was hoping to be able to fully and correctly detect collision with the circle not getting half buried in it, without having to apply force. [import]uid: 126161 topic_id: 23184 reply_id: 92903[/import]

This works. Use the force Luke.

[code]
display.setStatusBar(display.HiddenStatusBar)

local physics = require (“physics”)
physics.start()
physics.setGravity (0, 0)
physics.setDrawMode (“hybrid”)
_w = display.contentWidth
_h = display.contentHeight

local Scene = display.newGroup ()
local starCir = display.newCircle(Scene, 0, 0, 16 )
starCir.x = 460; starCir.y = 30;
physics.addBody( starCir, “dynamic”, { radius = 16})

local accX = 0
local accY = 0

local testWall = display.newRect (Scene, 0, 0, 480, 20)
testWall.x = _w/2; testWall.y = 310;
physics.addBody ( testWall, “static”)

local onAccelerate = function (event)
starCir:setLinearVelocity( event.yGravity*300, event.xGravity*300)
end
–[[
local moveBall = function ( event )
starCir:setLinearVelocity( accX, accY )

end
–]]
–Runtime:addEventListener (“enterFrame”, moveBall)
Runtime:addEventListener (“accelerometer”, onAccelerate)
[/code] [import]uid: 38820 topic_id: 23184 reply_id: 92911[/import]

Thanks for your help, it is very appreciated, i had to make some modifications for it to work on landscape but its working perfectly now. Here is the working code for landscape. Thanks again.

[lua]display.setStatusBar(display.HiddenStatusBar)

local physics = require (“physics”)
physics.start()
physics.setGravity (0, 0)
physics.setDrawMode (“hybrid”)
_w = display.contentWidth
_h = display.contentHeight
system.setAccelerometerInterval( 30 )

local Scene = display.newGroup ()
local starCir = display.newCircle(Scene, 0, 0, 16 )
starCir.x = 460; starCir.y = 30; starCir.isBullet = true;
physics.addBody( starCir, “dynamic”, { bounce = 0, friction = 0, radius = 16})

local testWall = display.newRect (Scene, 0, 0, 480, 20)
testWall.x = _w/2; testWall.y = 310;
physics.addBody ( testWall, “static”, {bounce = 0, friction = 0})

local onAccelerate = function (event)
starCir:setLinearVelocity((event.yGravity * 300) * -1, (event.xGravity * 300) * -1)
end

Runtime:addEventListener (“accelerometer”, onAccelerate)[/lua] [import]uid: 126161 topic_id: 23184 reply_id: 92976[/import]