3

I'm working on a text-based game involving a spaceship travelling between planets. Space is represented as a 2D plane. The ship has a current position, a destination and a speed.

Every minute, the game engine updates the current position of the ship, according to its current position, current destination and speed.

Knowing the ship speed (in unit per minute), I know the distance traveled by the ship in one minute. But I'm struggling to calculate the new position of the ship after it traveled that distance.

Let's say the starting position of the ship is (1,1), its destination position is (3,4) and the ship moving towards it at the speed of 1 unit per minute. What would be the new position at the ship after 1 minute, having traveled 1 unit?

Furthermore, what is a formula to calculate the new position (xP, yP) of the ship knowing its starting position (xA, yA), its current destination (xB, yB), and the distance traveled in 1 minute (D)?

enter image description here

PS: I should say that I've never learned mathematics so this might be very basic but I can't wrap my head around it and the problem might not be phrased well. But I'd be happy to provide more information if necessary.

clemlatz
  • 133
  • 1
    Welcome to MSE. Your question is phrased as an isolated problem, without any further information or context. This does not match many users' quality standards, so it may attract downvotes, or be closed. To prevent that, please [edit] the question. This will help you recognize and resolve the issues. Concretely: please provide context, and include your work and thoughts on the problem. These changes can help in formulating more appropriate answers. – José Carlos Santos Feb 20 '24 at 07:52
  • You will need to update your question with more information. Also, to solve this problem, the velocity vector is needed. – FriendlyNeighborhoodEngineer Feb 20 '24 at 08:05

1 Answers1

2

enter image description here Here is an image explaining everything. It's just the Pythagorean Theorem.

fleablood
  • 124,253