# Movement based off rotation.

• 05-16-2006, 10:50 AM
Mincher
Movement based off rotation.
Hi i'm trying to make a 2d game where i need the player's x and y positions to update based on the angle of rotation when they move. It's been a good few years since i even thought of programming and have forgotten the math.

Any help would be much appreciated!
• 05-16-2006, 10:55 AM
javatier
You could have two Variables one called xPos and yPos. It seems to be a very common way to get to set the players position.
• 05-16-2006, 11:02 AM
Mincher
Yes, but i want to move forward the way the sprite is facing rather than straight 4 directional movement.

I think it has something to do with storing the x and y positions and calculating the sin and cos of the angles but i'm jiggered if i can remember how it goes together.
• 05-16-2006, 06:22 PM
Mincher
Got it now :)
• 05-17-2006, 08:49 AM
Phaelax
step = amount the player moves each step
x += sin(angle)*step
y += cos(angle)*step

I might have flip-flop the sin and cos. If the rotation seems backwards, just swap them.