UE4 FInterpTo 解释

Interp我之前一直没时间去用过, 直到现在要用了才学= =, 源码格式:

CORE_API float FMath::FInterpTo( float Current, float Target, float DeltaTime, float InterpSpeed )
{
    // If no interp speed, jump to target value
    if( InterpSpeed <= 0.f )
    {
        return Target;
    }

    // Distance to reach
    const float Dist = Target - Current;

    // If distance is too small, just set the desired location
    if( FMath::Square(Dist) < SMALL_NUMBER )
    {
        return Target;
    }

    // Delta Move, Clamp so we do not over shoot.
    const float DeltaMove = Dist * FMath::Clamp<float>(DeltaTime * InterpSpeed, 0.f, 1.f);

    return Current + DeltaMove;
}

这边代码比较简单, 注意一点的是最后Dist值[0,1]之内的时候用的是DeltaTime*InterpSpeed的方法逼近值的,所以取值的时候要小心DeltaTime的取值如果不连tick函数的话

posted @ 2019-10-25 18:40  Cullchestar  阅读(2560)  评论(0编辑  收藏  举报