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函数的话


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM