Movement based off rotation.

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
May 2006
Posts
3

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!

2. Registered User
Join Date
Mar 2006
Posts
37
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.

3. Registered User
Join Date
May 2006
Posts
3
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.

4. Registered User
Join Date
May 2006
Posts
3
Got it now

5. Senior Member
Join Date
Mar 2004
Posts
635
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.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise