• Advertisement
Sign in to follow this  

diagonal movement (dumb question)

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by stro

x = 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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement