Public Group

# diagonal movement (dumb question)

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

first post on this forum so bear with me. i have a game which implements 8-way movement. i have a gamepice located at x, y and want him to move diagonally northeast. the gamepiece has a 'speed' property which indicates how far it moves during a frame. if the starting position is 0, 0 what are the final x,y if the game piece has a speed of 100? what would be the formula to work out the movement in any direction. i figure you need to use radians (in my case 45, 90, 135, 180 etc) and trig but its a long time since i left school and i threw out all my books! message to kids reading this board: don't burn your school books on your last day of school!! (no matter how tempting ;)

##### Share on other sites
Not too hard. You may have to multiply the y formula by -1 depending on what way you've set up your system.

x = 100cos(Angle)
y = 100sin(Angle)

##### Share on other sites
Quote:
 Original post by strox = 100cos(Angle)y = 100sin(Angle)

thanks for quick reply, but say the character was already at x=400, y=200 and has movement of 100, how would i use this equation taking into account the current postion to work out where it will end up?

##### Share on other sites
Since the first equations give you the relative offset from the origin, adding them to your current coords will result in the final pos.

x += 100cos(Angle)
y += 100sin(Angle)

##### Share on other sites
cool - didn't realise it would be that easy. thanks :)

• 11
• 20
• 12
• 10
• 35
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999857
×