Jump to content
  • Advertisement
Sign in to follow this  
bigbanggames

Vector2 reflection XNA

This topic is 1737 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
Advertisement
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!