Search code examples
javapointanimated

Java move player smoothly from one point to another


All I need is to claculate the new coordinites of a player based on a click and have the player move towards it smoothly. For example player is at (20, 20) and you click at (50, 80) how would i get it to move smoothly. I have tried many different thing mostly based on the pythagorean formula trying to calculate the new coord's by finding the hypotenuse then finding the same triangle with a smaller hypotenuse but there must be an easier way.


Solution

  • You can:

    1. Calculate the slope of the line segment formed by the origin and destination.
    2. For each time period until you reach the destination, adjust the new coordinate based on the slope calculated in step 1.