player.move(50, 50, duration);
[50,50] here is the offset.
The player then calculates the final location in pixels and stores it as endPos.
direction is then calculated by the player class as ||[50,50]|| (normalize the input X and Y vector).
Distance is of course the length of the vector [50,50]. These are not passed to the player but calculated by the player class.
Then the player calculates how fast to move per second.
moveVector = (direction * distance) / duration;After this, each logical update (which should use a fixed time-step) moveVector is added to the player’s position after being multiplied by the amount of time that has passed.
When the amount of passed time exceeds duration, the player’s position is specifically set to endPos to avoid floating-point and time-related errors.
L. Spiro