collision - Bouncing a ball off a surface -


I am in the midst of writing games like breakout, and I was thinking how exactly I can bounce the ball a surface.

I went through an easy way to move velocity by 90 degrees, which was:

  [vx, vy] - & gt; [-vy, vx]  

What (surprisingly) did not work so well if I know the position of the ball and the rashness, as well as the ball will be hit (but its Rather than bouncing it) How can I bounce from that point?

Obligations:

  • I am using integer mathematics (no FPs anywhere)
  • All my surfaces are simple flat surfaces (vertical, Horizontal, or a block)
  • I want to bounce at only 90 degrees angle
  • All collisions are completely elastic (this is a breakout - no need for friction , Etc.)

I do not need any language specific code if someone does this in order to do this properly Can provide a small, mathematical formula that will work well for me

Thanks!

You need to calculate the normal vector at the point of contact. With normal, the component of velocity will change, while reducing the velocity of velocity from the normal will be similar.

It is easy to calculate normal for horizontal / vertical surfaces. For more complex surfaces, it can depend on the equation of surface etc.

In addition, it assumes that the energy of the ball does not change. If you take the rotation of friction / heat loss / ball etc., then it can be complicated.


Comments