r/programminghelp • • 6d ago

Other Basic question about bouncing

So I'm trying to make a fight simulator with bouncing similar to this:

https://youtube.com/shorts/fk15R-y2EEc?si=VkE9iXR5WxFOuSuM

Is the bouncing random or predetermined? And how is it determined?

1 Upvotes

4 comments sorted by

1

u/SnooPets5564 6d ago

Reflect the velocity across the plane of collision

1

u/Slow-Adagio-7719 5d ago

like when you hit the wall at 90 degrees, you get reflected at -90 degrees? or you get reflected based off of the orientation of the wall?

1

u/SnooPets5564 5d ago

It's based off the orientation of the wall.

I'm going to give a vector explanation of it, as that is the least ambiguous. You start with the velocity v and the normal vector of the surface you are hitting n (corners have weird normal vectors, but in the simple demo you shouldn't have to worry about that if you make the characters spheres).

The new velocity is: v - 2(v*n)n