Page 1 of 1

Implementing bouncing with HC

Posted: Mon Nov 12, 2018 9:35 am
by aidalgol
I am trying to implement really basic physics using HC for collision detection, and I seem to have not implemented bouncing correctly. I have a moving ball and a static square, and I am trying to use the separating vector returned by HC.collisions() to change the direction of the ball's velocity so that it bounces off the square when it collides. What is instead happening is that the ball hits the square and travels slower almost completely straight downwards (positive Y axis).

My minimal reproduction of this issue is here: https://gitlab.com/aidalgol/hc-love-collision-bug

Re: Implementing bouncing with HC

Posted: Mon Nov 12, 2018 6:28 pm
by pgimeno
The separating vector is not the bounce direction. It's more like the collision normal, but keep in mind it's not a unit vector.

Try with this: http://mathworld.wolfram.com/Reflection.html

Re: Implementing bouncing with HC

Posted: Tue Nov 13, 2018 9:20 am
by aidalgol
pgimeno wrote: Mon Nov 12, 2018 6:28 pm The separating vector is not the bounce direction. It's more like the collision normal, but keep in mind it's not a unit vector.

Try with this: http://mathworld.wolfram.com/Reflection.html
Ah, that explains the 90° angle. Thanks! I shall read up on reflection.