• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# 2D Vector Reflection ?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1HUWUWA  Members   -  Reputation: 122

Like
Likes
Like

Posted 29 June 2003 - 11:32 AM

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.

### #2Yohumbus  Members   -  Reputation: 152

Like
Likes
Like

Posted 29 June 2003 - 11:42 AM

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]

### #3Cedric  Members   -  Reputation: 158

Like
Likes
Like

Posted 29 June 2003 - 01:25 PM

WallN must be normalized.

### #4JavaCoolDude  Members   -  Reputation: 670

Like
Likes
Like

Posted 29 June 2003 - 01:40 PM

I like this better;
V-=2*Normal_wall*(Normal_wall.V)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS