I am currently trying to move a sprite in the direction it’s facing. I have looked through stack overflow and have tried what they said to do but it just won’t work. I don’t really know trig or how to apply it.
This is my code for movement:
if (kbstate.IsKeyDown(Keys.Left))
{
angle -= .7f;
}
if (kbstate.IsKeyDown(Keys.Up))
{
shipPos.Y -= shipSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
//want to change
}
if (kbstate.IsKeyDown(Keys.Right))
{
angle += .7f;
}
if (kbstate.IsKeyDown(Keys.Down))
{
shipPos.Y += shipSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
This is how I draw the character:
_spriteBatch.Draw(shipTexture, shipPos, new Rectangle(0, 0, shipSize, shipSize), Color.White, MathHelper.ToRadians(angle), origin, 1f, SpriteEffects.None, 1);
What code should I add to make the sprite move in the direction it’s facing?