Problem while inverting direction on collision

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
BagarraoEduardo
Prole
Posts: 3
Joined: Thu Apr 19, 2018 1:20 pm

Problem while inverting direction on collision

Post 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.
Attachments
main.lua
(4.62 KiB) Downloaded 98 times
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Problem while inverting direction on collision

Post 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.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Problem while inverting direction on collision

Post 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".
BagarraoEduardo
Prole
Posts: 3
Joined: Thu Apr 19, 2018 1:20 pm

Re: Problem while inverting direction on collision

Post 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 :)
BagarraoEduardo
Prole
Posts: 3
Joined: Thu Apr 19, 2018 1:20 pm

Re: Problem while inverting direction on collision

Post 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:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 61 guests