Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D Vector Reflection ?

Started by HUWUWA Jun 29, 2003 at 5:32 PM 2 replies 30k views
Original Post
HUWUWA
HUWUWA
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.
Yohumbus
Yohumbus
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
Cedric
Cedric
WallN must be normalized.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.