Gnomad: Framerate Independent Interpolation


Sep 22 2023

The goal this week was to continue implementing new movement mechanics and fixing several bugs thereof. After the implementation of the HSM, it was much easier to implement the ground pound, slide, wall slide, and wall jump mechanics than it would have been without.

One particularly interesting bug that we came across with our falling state was that it was considerably different in a build than it was in the editor. As it turns out, the suspect line was the following:

context.rb.velocity = Vector2.Lerp(
    new Vector2(context.rb.velocity.x, MovementStats.fallSpeed),

Thankfully, I found a relevant video by Simon Dev that covered exactly what we were experiencing, and also pointed us away from using simply delta-time as the interpolant. Using this advice, I implemented a utility function for this purpose shown below:

public static class Utils
    public static float GetInterpolant(float k){
    return Mathf.Abs(1.0f - Mathf.Pow(k, Time.deltaTime));