Download

FInterpTo is not Interpolate to target value fully

I’m trying to implement crouching in C++ using FInterpTo in Tick and trying to set capsule half height from 96 to 48. With below code capsule height is interpolating to 65 instead of 48 and its directly linked to capsule radius. If I change capsule radius to 48 from 65 then FInterpTo is interpolating to 48. I’m not sure why capsule height interpolation stops at capsule radius? can anyone please help me in figuring it out or a way to make it interpolate till 48 even if capsule radius is set to 65. Thanks in advance

FInterpTo Code in Tick: GetCapsuleComponent()->SetCapsuleHalfHeight(FMath::FInterpTo(GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight(), TargetHeight, DeltaSeconds, 10.f));

I think it’s because you use FInterpTo, in which you’re changing the distance we’re interpolating by interpolating the actual “start” value. This messes up the math.
What you want to use is FInterpConstantTo.

Hi I tried FinterpConstantTo and its not interpolating till the target value. It stops at capsule radius count. Placed FinterpConstantTo in Tick and interpolation is very slow irrespective of InterpSpeed

Code in Tick: GetCapsuleComponent()->SetCapsuleHalfHeight(FMath::FInterpConstantTo(GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight(), TargetHeight, DeltaSeconds, 10.f));

The code looks correct. 10.f interpspeed in this case means you’ll advance 10.f towards TargetHeight per second.
I’d guess something else is setting the capsule half height as well somewhere in your code.

Not sure if that makes sense given the problem you are having, but shouldn’t it be GetScaledCapsuleHalfHeight instead of GetUnscaledCapsuleHalfHeight? To me it sounds liked the latter just uses the scale it had when the game started, you’d need the current scale of your capsule though in order for the interpolation to work properly. Haven’t really tested it though.

Realistically, you’ll probably need to use a Linear Interpolate if you want to move the target / start locations.