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