Sign in to follow this  
jonod

diagonal movement (dumb question)

Recommended Posts

jonod    122
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
Stephen R    721
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
jonod    122
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
Stephen R    721
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this