I'm currently in the middle of writing a game like Breakout, and I was wondering how I could properly bounce a ball off a surface.
I went with the naive way of rotating the velocity by 90 degrees, which was:
[vx, vy] -> [-vy, vx]
Which (unsurprisingly) didn't work so well. If I know the position and veocity of the ball, as well as the point the ball would hit (but is going to instead bounce off of) how can I bounce it off that point?
Constraints:
I don't need any language specific code. If anyone could provide a small, mathematical formula on how to properly do this that would work fine for me.
Thanks!
Assuming you are only going to be bouncing off of either vertical or horizontal surfaces, you can just negate the velocity in the X or Y directions, respectively.
So, if you have [vx, vy], and it bounces off a vertical wall, you will have [-vx, vy].
If you have [vx, vy], and it bounces off a horizontal wall, you will have [vx, -vy].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With