Jump to content
  • Advertisement
Sign in to follow this  

Help calculating x,y position of traveling ship

This topic is 3304 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

I've got a ship in traveling and I want to represent it's location on a 2d map. The ship starts at an X,Y which is known and ends at a known X,Y. I also know the time the fleet started moving and how long it'll take to arrive. Using that info, is there a way to determine what x,y the ship would be at at a given time into the trip? Like say I wanted to know current, I could calculate the time traveled so far as 10 minutes, and use that to derive the current X,Y... Thanks for any help. Chu EDIT: I should point out that accelleration is constant in my game.

Share this post

Link to post
Share on other sites
Let startpos=(X,Y), endpos=(Xfinal, Yfinal). Then:

dir = endpos-startpos

intermediateposition = startpos + dir*(elapsedtime/wholetimeoftrip)

Hopefully this makes sense, the position you want is just the start position + the direction of movement scaled by the current time of travelling compared to the total time.

Share this post

Link to post
Share on other sites
I'm assuming you meant constant speed (therefore acceleration too).

In the following equations these variables are used:
"ship starts at an X,Y" -> startX, startY
"ends at a known X,Y" -> endX, endY
"time the fleet started moving" -> startTime
"how long it'll take to arrive" -> tripTime
"what x,y the ship would be at at a given time" -> curX, curY

Plug the result of the first equation into the other two to get the ship's (X, Y) coordinate.

relTime = (curTime - startTime) / tripTime
curX = startX + (endX - startX) * relTime
curY = startY + (endY - startY) * relTime

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!