Dynamic, static or kinematic for an object that moved by accelerometer?

I have this screen:

0MOE7.png

I want this ball to be moved using accelerometer and collide with the walls.

When I declared it as dynamic it moved but not collide, when I declared it as dynamic it had a strange trembling in its movement and after a while stop collide and went out of the borders. My code (for physics and movement function) is:

 

function onTilt( event )

ball.x = (ball.x + event.xGravity * 20)
ball.y=(ball.y+ event.yGravity * 20)
end

physics.addBody ( mazepart1, “static” ,physicsData:get(“mazepart1”))
physics.addBody ( mazepart1, “static” ,physicsData:get(“mazepart2”))
physics.addBody (borders, “static” ,physicsData:get(“borders”))
physics.addBody ( ball, “dynamic” ,physicsData:get(“ball1”))

Runtime:addEventListener( “accelerometer”, onTilt )

Any idea what I am doing wrong?

I think you have said that you declared it as dynamic twice, but I’ll assume the first was meant to read ‘kinematic.’

The reason your ball moved through the walls when it was kinematic is because that is the nature of kinematic objects. They don’t react to gravity or collisions:

http://developer.coronalabs.com/content/game-edition-physics-bodies#body.bodyType

The reason the dynamic method caused the ball to wobble is that you are setting the x and y value of the ball directly, rather than making use of the gravity effects upon the ball. Take a look at the ShapeTumbler source included in the CoronaSDK application directory’s samples.

I think you have said that you declared it as dynamic twice, but I’ll assume the first was meant to read ‘kinematic.’

The reason your ball moved through the walls when it was kinematic is because that is the nature of kinematic objects. They don’t react to gravity or collisions:

http://developer.coronalabs.com/content/game-edition-physics-bodies#body.bodyType

The reason the dynamic method caused the ball to wobble is that you are setting the x and y value of the ball directly, rather than making use of the gravity effects upon the ball. Take a look at the ShapeTumbler source included in the CoronaSDK application directory’s samples.