I want to create a maze game using gyroscope to move the ball. The problem is that the ball collide with the walls as it should but after a while it passes through the walls. I can’t explain why.
Here is my code:
ball=display.newImage("ball1.png") ball.x=30 ball.y=display.contentCenterY ball.name="ball" physics.addBody ( mazepart1, "static" ,physicsData:get("mazepart1")) physics.addBody ( mazepart1, "static" ,physicsData:get("mazepart2")) physics.addBody (ball, "dynamic" ,physicsData:get("ball1")) top=display.newLine( 0, 1, display.contentWidth, 1) physics.addBody ( top, "static") bottom=display.newLine( 0, display.contentHeight, display.contentWidth,display.contentHeight) physics.addBody ( bottom, "static") left=display.newLine( 1, 0, 1, display.contentHeight) physics.addBody ( left, "static") right=display.newLine( display.contentWidth-1, 0, display.contentWidth-1, display.contentHeight) physics.addBody ( bottom, "static") local function onGyroscopeDataReceived( event ) -- Calculate approximate rotation traveled via deltaTime. --physics.setGravity( 10 \* event.xGravity, -10 \* event.yGravity ) local deltaRadiansX = event.xRotation \* event.deltaTime local deltaDegreesX = deltaRadiansX \* (180 / math.pi) local deltaRadiansY = event.yRotation \* event.deltaTime local deltaDegreesY = deltaRadiansY \* (180 / math.pi) ball.x = ball.x + deltaDegreesX \*5 ball.y = ball.y + deltaDegreesY \*5 end -- Set up the above function to receive gyroscope events if the sensor exists. Runtime:addEventListener( "gyroscope", onGyroscopeDataReceived )
Any idea why may this happen?