I'm talking about where if you press a directional key once you walk over to the adjacent tile and can't do any other actions during the walk. I can get my character to move one tile width, but my trouble is animating the walk and having the character actually walk to the next tile, rather than teleport. The research I've done has pointed me in the direction of interpolation, but I don't really understand how to get it working.


1 Answer 1


The easiest way is to use linear interpolation (AKA lerp) over time.

Let's say you want you character to move from posA to posB. You calculate it's current position every frame from those two positions, the current time (incremented by a delta time every frame), and the wanted movement duration, as follows:

float t = currentTime / moveDuration
vector currentPos = posA  + (posB - posA) * t

This movement might feel a bit mechanical but that's a good first step, if you want to go further, look into easing functions:

  • \$\begingroup\$ Make sure to do check for 0 < t < 1 in order to disable player input during this time. The last thing you want is seeing something unexpected if the player tries other actions during the walk, such as buffering a lot of walk actions that won't stop for a long time. \$\endgroup\$
    – ChrisC
    Aug 17, 2012 at 2:09
  • \$\begingroup\$ Thanks! I'll look into this and see if I can get it working. \$\endgroup\$ Aug 17, 2012 at 14:29
  • \$\begingroup\$ I've gotten the interpolation working, and I'm getting a the pixel values for everything in between 128 and 144, which is great. Thanks for the help. My problem now is getting the position of the image to update every time the position of the image is changed. I'm using Slick link and I'm not sure where to go from here. I'll look around the slick forums for this, but if anyone knows anything and can post it here it would be appreciated. \$\endgroup\$ Aug 17, 2012 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .