1 min
When adding animations to things in code, a lerp animation is the easiest of them all, by taking two points and calculating the average point of the two you can easily add a little magic to your game. All you need to remember is that this needs to be isolated to game-side mechanics otherwise you can expect undefined behaviour.
z_position = 0.9f * z_position + 0.1f * z_target;
Although the smooth end on the Lerp is pretty satisfying, a constant speed can also be desired as it allows for movement that can be predicted.
if (magnitude <= max_movement)
{
z_position = z_target;
}
else
{
z_position += sign(z_target - z_position) * move_speed;
}
To give weight to the pieces - a slow rise and a fast fall makes the piece feel heavier.
Subscribe to this blog via RSS.
Blog 17
Snake 4
Birdman 2
Blog (17) Low-level programming (17) Snake (4) Endless runner (2) Birdman (2) Chess-com (6)