Simple Animations to Add Magic

Simple Animations to Add Magic

Apr 20, 2018. | By: Ben Windley
1 min

Simple Lerp (Linear Interpolation) Animation

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.

Psuedocode

z_position = 0.9f * z_position + 0.1f * z_target;

Simple Move-Towards Animation

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.

Psuedocode

if (magnitude <= max_movement)
{
    z_position = z_target;
}
else
{
	z_position += sign(z_target - z_position) * move_speed;
}

Combination of both

To give weight to the pieces - a slow rise and a fast fall makes the piece feel heavier.

Social Links

linkedin