Hey there,
I’m trying to create a simple pong game, but am coming up against a Physics problem I can’t diagnose.
Once the ball goes offscreen I remove it, set it to ‘nil’, and then create a new ball and ‘serve’ it. As you can see in this short video, this new ball gets stuck.
https://dl.dropboxusercontent.com/u/761630/pong-physics-problem.mov
I can see in my terminal debugs (also in the video) that the yVelocity is positive, but as soon as it hits the bottom wall it should be inverted…
– If the ball hits the top and bottom walls
local function topBottomCollision( self, event )
if( event.phase == “began” ) then
yVelocity = yVelocity * -1 – reverse the Y direction
ball:setLinearVelocity( xVelocity, yVelocity )
return true
end
end
I’ve attached game.lua and the two class files it refers to (). There’s not much to it. Most of the code is creating the walls for the ball to bounce off.
I’m using Corona Version 2014.2189 (2014.3.6).
Thanks so much for any help you can offer!
Rich