XNA Vector2 Rotation Question

Posted by Tom Allen on Stack Overflow See other posts from Stack Overflow or by Tom Allen
Published on 2010-04-20T20:20:27Z Indexed on 2010/04/20 20:23 UTC
Read the original article Hit count: 274

Filed under:
|

I'm messing about with some stuff in XNA and am trying to move an object around asteroids-style in that you press left and right to rotate and up/down to go forwards and backwards in the direction you are pointing.

I've got the rotation of the sprite done, but i can't get the object to move in the direction you've pointed it, it always moves up and down on the x = 0 axis.

I'm guessing this is straight forward but I just can't figure it out. My "ship" class has the following properties which are note worthy here:

Vector2 Position
float Rotation

The "ship" class has an update method is where the input is handled and so far I've got the following:

public void Update(GameTime gameTime)
{
    KeyboardState keyboard = Keyboard.GetState();
    GamePadState gamePad = GamePad.GetState(PlayerIndex.One);

    float x = Position.X;
    float y = Position.Y;

    if (keyboard.IsKeyDown(Keys.Left))  Rotation -= 0.1f;
    if (keyboard.IsKeyDown(Keys.Right)) Rotation += 0.1f;
    if (keyboard.IsKeyDown(Keys.Up))    y -= ??;
    if (keyboard.IsKeyDown(Keys.Down))  y += ??;

    this.Position = new Vector2(x, y);
}

Any help would be most appreciated!

© Stack Overflow or respective owner

Related posts about XNA

Related posts about rotation