Spielerando

Lerp and smoothstep

The small helpers for blending one number into another: halfway between two values, turning health into a bar, a soft fade near an edge. They are the building blocks behind nearly every smooth effect in a game.

When you need it

When a value should follow another one softly: a health bar, music getting louder as you get closer, a character turning the short way round, or something gliding towards a target.

Say this to your AI

Use lerp and smoothstep from Spielerando so the music fades in as I walk towards the fire, and the same on fast and slow computers.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

Settings

Your AI gets the code

The finished code and math come through the Spielerando connection, so your AI can use them right away. Connect your AI

Common questions

what is lerp in a game

Lerp is short for blending in a straight line. You give it two values and how far along you are, and it hands back the value in between. A quarter of the way from 0 to 100 is 25.

why is my movement faster on a faster computer

Moving a fixed share of the distance every frame runs faster when there are more frames. Use the glide helper in this recipe instead. It looks at the time since the last frame, so it runs the same everywhere.

how do i turn a character the short way round

Do not blend the two angles directly, or the character spins the long way when crossing the back. Blend the shortest turn between them. The angle helper here does exactly that.