Page 1 of 1

Problem while inverting direction on collision

Posted: Thu Apr 19, 2018 7:05 pm
by BagarraoEduardo
Hello all! :awesome: :awesome:

I'm starting to make a single game in LOVE 2D(Pong) and I'm struggling in the following things:

- Problems on inverting direction when a ball collides on paddle --> The ball goes in one direction, but on the beginContact() function I inverted direction but still don't work;
- In the collision of the ball and the paddle the ball pushes the paddle off the screen --> I'm thinking the reason is that the ball direction don't invert, but I want to avoid all kind of impulse to be applied on the paddle.

I've searched and I don't know what to do. Thanks in advance guys :awesome !!!

P.S.: Together I sent my main.lua file.

Re: Problem while inverting direction on collision

Posted: Fri Apr 20, 2018 5:46 am
by grump
I think you're gonna have a hard time making Pong work with accurate physics simulation, and you would be better off making your own ball and paddle 'physics' that is better suited for this type of game.

Re: Problem while inverting direction on collision

Posted: Fri Apr 20, 2018 6:52 am
by ivan
BagarraoEduardo wrote: Thu Apr 19, 2018 7:05 pm - In the collision of the ball and the paddle the ball pushes the paddle off the screen -->
Depends on the mass and velocity of the objects. Heavier bodies tend to push lighter bodies, that's just how physics works. A naive solution could be increase the density of the paddle.
If you set the type of the paddle to "kinematic" it won't respond to collisions at all.
Alternatively, a prismatic joint can constrain motion to a specific axis.
Also, make sure the "restitution" coefficient of both the paddle and ball is set to "1".

Re: Problem while inverting direction on collision

Posted: Fri Apr 20, 2018 11:12 am
by BagarraoEduardo
grump wrote: Fri Apr 20, 2018 5:46 am I think you're gonna have a hard time making Pong work with accurate physics simulation, and you would be better off making your own ball and paddle 'physics' that is better suited for this type of game.
Yeah you're right :) I'll started that way but I thought it would be a bad approach, but I'll make it again from scratch :D :D ty :)

Re: Problem while inverting direction on collision

Posted: Fri Apr 20, 2018 11:13 am
by BagarraoEduardo
ivan wrote: Fri Apr 20, 2018 6:52 am
BagarraoEduardo wrote: Thu Apr 19, 2018 7:05 pm - In the collision of the ball and the paddle the ball pushes the paddle off the screen -->
Depends on the mass and velocity of the objects. Heavier bodies tend to push lighter bodies, that's just how physics works. A naive solution could be increase the density of the paddle.
If you set the type of the paddle to "kinematic" it won't respond to collisions at all.
Alternatively, a prismatic joint can constrain motion to a specific axis.
Also, make sure the "restitution" coefficient of both the paddle and ball is set to "1".
I'll make the game from scratch without the physics, I only don't know how I'll apply the collisions in that way ;) ty anyway :awesome: :awesome: