Sign in to follow this  

Vector2 reflection XNA

Recommended Posts

bigbanggames    142

My player sprite holds its own speed as a Vector2, its own direction as a Vector2 so in the Update Method I set the player's position (a Vector2) to:

Position += Direction * Speed;


I have a polygon sprites class that has a property that returns the left normal between the two points that make up a given line segment.


I thought I could just use player.Direction = Vector2.Reflect( player.Direction, lineSegment.LeftNormal);

That did not work. I also tried using the Vector2.Negate(player.Direction); this also did not work.


I used the left normal because the polygons are wound clockwise.


Is the direction the player is traveling the same as the incidence angle?

Why would this not be working?


thanks in advance!




Share this post

Link to post
Share on other sites
unbird    8336
I think Vector2.Reflect should work the way you use it. Make sure the edge normal is unit length (docs don't state that they need be, but for the reflection formula they normally should).

Share this post

Link to post
Share on other sites
phil_t    8084

And define "did not work". What happened? What did the values look like in the debugger?

Edited by phil_t

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this