Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to move the sprite in the direction it's rotated.
C#
if (newState.IsKeyDown(Keys.W))
            {
                airplanePos += new Vector2(Convert.ToInt32(Math.Sin(airplaneAngle * 360)), Convert.ToInt32(Math.Cos(airplaneAngle * 360)));
            }
Posted
Updated 26-Nov-12 3:54am
v3
Comments
ZurdoDev 26-Nov-12 9:58am    
What's the problem?
MaXx0r 26-Nov-12 10:08am    
It doesn't move in the right direction, I guess the direction calculation is wrong.

1 solution

I BELIEVE it should be like this, although I haven't tested it:

C#
if (newState.IsKeyDown(Keys.W))
            {
                airplanePos += new Vector2(Convert.ToInt32(Math.Cos(airplaneAngle * 360)), Convert.ToInt32(Math.Sin(airplaneAngle * 360)));
            }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900