Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


#ActualL. Spiro

Posted 14 February 2013 - 04:13 PM

You can’t do it properly that way due to floating-point imprecision. You need to pass the actual target location or the actual offset to the target location in pixels.

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

#1L. Spiro

Posted 14 February 2013 - 04:12 PM

You can’t do it properly that way due to floating-point imprecision. You need to pass the actual target location or the actual offset to the target location in pixels.

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 frame 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

PARTNERS