So, I have a ping pong game, and I am in the process of modifying it, so that when the player is moving their pong upward, the ball will bounce back with a positive “y” linear velocity. But, it is not working out. If the ball is coming towards the player from the top and the player is moving upward, the ball bounces back going down.
I tried doing this:
local absV = math.abs local function ballCollision(self, event) local vx3, vy3 = self:getLinearVelocity() local phase = event.phase local other = event.other.id local pongvx, pongvy = event.other:getLinearVelocity() if( phase == "began" ) then if( other == "player") then if (pongvy \> 0) then timer.performWithDelay( 1, function() self:setLinearVelocity( -vx3, absV(vy3) ) end ) end end end return false end
But it did not work.
Feel free to ask if you need a better explanation and any code.