Bouncing a ball off a surface
Posted
by Sagekilla
on Stack Overflow
See other posts from Stack Overflow
or by Sagekilla
Published on 2010-05-16T18:55:47Z
Indexed on
2010/05/16
19:00 UTC
Read the original article
Hit count: 208
Hi all, 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 180 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?
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. I also need this to work with integer positions and velocity (I can't use floating point anywhere).
Thanks!
© Stack Overflow or respective owner