Sign in to follow this  

Vector2 reflection XNA

This topic is 1521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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

This topic is 1521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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