Doubt about VInterpConstantTo

I’ve been using FInterpConstantTo quite often and it always worked the way i expected, i set the interpolation speed to how much i want to progress in 1 second and that works, but if i do the same with VInterpConstantTo i get different values than what i was expecting. Example:

void ATest::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	TestTime += DeltaTime;

	const FVector TargetValue = FVector(0.25f);

	if (!TestValue.Equals(TargetValue))
	{
		TestValue = FMath::VInterpConstantTo(TestValue, TargetValue, DeltaTime, 0.25f);

		LOG("%f  %s", TestTime, *TestValue.ToString());

		if (TestValue.Equals(TargetValue))
		{
			TestValue = FVector::ZeroVector;
			TestTime = 0.0f;
		}
	}
}

This example is taking me 1.73 seconds to get from 0.0f to 0.25f, if i do this example with floats and FInterpConstantTo it takes 1 second to get from 0.0 to 0.25f which makes sense since the interpolation speed is 0.25f. Shouldn’t VInterpConstantTo increase all the components individually like it’s 3 FInterpConstantTo and also take 1 second?

To understand the behavior of FMath::VInterpConstantTo, you have to understand what’s it’s interpolating between. FMath::VInterpConstantTo does not interpolate between the individual components of two vectors, but instead between two points in space. The FVector(0.25, 0.25, 0.25) can be described as an arrow from the origin to the point (0.25, 0.25, 0.25) in space. The distance that is being interpolated between when going to the zero vector is the length of FVector(0.25, 0.25, 0.25), which is 0.4330127019f. This is why it’s taking 1.73 seconds.

TL;DR
FMath::VInterpConstantTo interpolates between positions in space, not component values. If you want to interpolate between component values, use three calls to FMath::FInterpConstantTo for each component of the vector.

Thanks for the clarification, so what can i say to myself when i’m setting the interpolation speed? In floats i just think, this is how much i want it to interpolate per second, with vectors apparently it’s not as simple as that.

Imagine you drew a line between the two vectors you’re interpolating between in space. The interpolation speed is how fast the interpolation will move along that line. In this particular case, if you moved an object based on the FVector you’re interpolating, it would be moving at 0.25 cm/second.

1 Like

I see, thnks !