Hello well… the title says it all I was just wondering that because I saw some people were saying Lerp is worse for performance and to go to the alternative FInterpTo or FInterpConstantTo. is that true?? idk im just thinking why not put a clamp on it but hey what do I know any advice would be much appreciated.
Unless you’re calling them thousands of times a second, I wouldn’t worry about it, the performance difference is going to be negligible considering everything else that’s going on.
As an aside, Lerp is a much cheaper operation as it is much simpler, just look at the implementation yourself;
template< class T, class U >
static FORCEINLINE_DEBUGGABLE T Lerp( const T& A, const T& B, const U& Alpha )
{
return (T)(A + Alpha * (B-A));
}
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;
}