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函數的話