#### Archived

This topic is now archived and is closed to further replies.

# Line movement

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

## Recommended Posts

I''m setting up for an engine that will make games similiar to the old Kings Quest games. I''m going to make it so the player can click anywhere on the screen and he''d move to that place in a straight line. I just would like to figure out how to get these to points, lets say from 50,50 to 100,150 into a simple ratio for movement. For example, int this the character would move in a 1:2 ratio. to get to that location. I can do this in my head by subtracting 100-50, and 150-50 leaving me with a 50:100 ratio which I can easily simplify. How can I get the computer to be able to simplify in a similiar way? Thanks in advance. --Muzlack

##### Share on other sites
Just a thought... the ratio would be a percent of the distances to be travelled along the x and the y. Or, in other words,
  float ratio = (float)(DestinationX - PlayerX) / (float)(DestinationY - PlayerY);
Hmm... looks right. With your values I believe you would get 0.5f, which you then times with the distance you player has to travel along the y, giving you a 50 and a 50. (ratio > 1.0f if there was more x to travel than y, but then they would still equal). Calculate that ratio when the command to move is given, and calculate a separate ratio everytime the player has moved a space. The difference in the ratios (> or <) shows you if *this* time the player has to move to the east, or south.
Then, I might just be pulling all this out my arse...
-Tok

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Feel free to email me HERE
*Howdy Kids, Do /YOU/ know what time it is? It''s tangent time* -Baldor the Bold

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631780
• Total Posts
3002314
×