I’m officially stumped. After completing a project, I noticed an issue with my physics that I’m not sure how to fix. I’ve striped down the code to the very basics which shows the problem. Originally, I started with Corona’s sample code ‘ShapeTumbler’ which does not seem to have the problem.
The Problem: When running on the device (not simulator), the ball gets ‘stuck’ when it is tilted into a corner or touching multiple surfaces (from what I’ve seen). As a test, I added drag code (not included here) to move the ball when it gets stuck, and I am able to get it moving again but it only gets stuck again. Rolling the ball around the screen works, but when it comes to rest in a corner and I try to tilt again, the ball is stuck or the physics gets out of sync and simply does not respond. Any clues? I’m guessing its something so simple, but I feel I’ve just stared at it too long. Thanks in advance.
[code]
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
physics.setGravity( 0, 9.8 )
system.setAccelerometerInterval( 100 )
function onTilt( event )
physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 * event.yGravity ) )
end
Runtime:addEventListener( “accelerometer”, onTilt )
display.setStatusBar( display.HiddenStatusBar )
local ball = display.newImage(“soccer_ball.png”)
ball.x = 40; ball.y = 80
borderBodyElement = { friction=0.5, bounce=0.3 }
local borderTop = display.newRect( 0, 0, 320, 20 )
physics.addBody( borderTop, “static”, borderBodyElement )
local borderBottom = display.newRect( 0, 460, 320, 20 )
physics.addBody( borderBottom, “static”, borderBodyElement )
local borderLeft = display.newRect( 0, 20, 20, 460 )
physics.addBody( borderLeft, “static”, borderBodyElement )
local borderRight = display.newRect( 300, 20, 20, 460 )
physics.addBody( borderRight, “static”, borderBodyElement )
physics.addBody( ball, { density=0.9, friction=0.9, bounce=0.3, radius=38 } )
[/code] [import]uid: 10593 topic_id: 3389 reply_id: 303389[/import]