Objects Going through other objects

I am creating a basic game that uses the accelerator to move a ball. When you tilt the iPhone the ball moves to the left or right depending on which way you tilted the device. I placed an image that was static so when the ball hit the bar (image) it would bounce back but instead the ball goes right through the bar (image) with some resistance. What can I can do to make the ball not go through the bar(image)?

[code]–Accelerometer
local motionx = 0
local motiony = 0

local function onAccelerate( event )
motionx = 30 * event.yGravity
motiony = 1 * event.xGravity
end
Runtime:addEventListener (“accelerometer”, onAccelerate)

local function moveball (event)
circle.x = circle.x - motionx
circle.y = circle.y - motioy
end
Runtime:addEventListener(“enterFrame”, moveball)
[/code] [import]uid: 82872 topic_id: 19606 reply_id: 319606[/import]

Don’t use the enterFrame listener to move the ball like that. You should either control the gravity or simply set the linear velocity of the ball like this. Tweak or try to use gravity instead until you achieve the result you want? This should avoid the ball from passing through the obstacles.

[code]
local function onAccelerate( event )

circle:setLinearVelocity(event.xGravity * 1000, event.yGravity * 1000)

end

Runtime:addEventListener (“accelerometer”, onAccelerate)
[/code] [import]uid: 12979 topic_id: 19606 reply_id: 75732[/import]

Check out this thread I had a similar problem and the help I was given manage to fix this(Thanks) but as Chang Kian Boon suggested that was my problem too.

Link: https://developer.anscamobile.com/forum/2011/11/14/tilt-vs-static-objects-goes-through

Best of Luck,
LeivaGames [import]uid: 30314 topic_id: 19606 reply_id: 75772[/import]