2D Vector Reflection ?

Started by
2 comments, last by HUWUWA 20 years, 9 months ago
Hi guys, I''m making a breakout clone and need to reflect the ball off the wall. I thought I had the perfect formula but I added angled walls and the reflection doesn''t work right now. I was basing the reflection off the wall normal. It would be nice to have a formula that can take any normal and reflect the ball direction, then I don''t have to do all the if...then tests. I guess I don''t really care though so long as it''s fast. Thanks.
Advertisement
Arg I know this one if I can just remeber it from POV-Ray!

ah here we go...
Vect1 is the direction of the ball before hitting the wall
Vect2 is after the wall
WallN is the normal of the wall
DOT is the dot product


Vect2 = Vect1 - 2 * WallN * (WallN DOT Vect1)

note that this will work for 3D vectors too

[edited by - Yohumbus on June 29, 2003 6:43:00 PM]
ASCII stupid question, get a stupid ANSI
WallN must be normalized.
I like this better;
V-=2*Normal_wall*(Normal_wall.V)

This topic is closed to new replies.

Advertisement