You have a ball heading for a surface and you want the ball to bounce correctly…

To make this happen, you’ll need to reflect the inbound direction of the ball off of the surface it hits in order to figure out where the ball should go.
The math for this is pretty simple;
InboundVector – 2 * (InboundVector . surfaceNormal) * surfaceNormal
Sounds easy enough so let’s give it a go…

I’ve broken down each of the pieces of the math into simple steps and shown them with comments.
The code has been set up to make the ball bounce when it gets below 0.5f in the Y. This way, it makes it look like the ball has hit the surface although it’s actually just hitting a specific height before getting reflected.
Once reflected, the ball will keep moving up until it gets to 4m off the ground and then it’ll pick a new source point and go again.
Hope that helps!



Leave a comment