How does VInterpTo work?

Hi!

I’ve got not much idea about game developing and now I want to do move an actor smoothly. Searching I’ve found that I could use VInterpTo, but I don’t know how this method works:

I don’t understand interpolation. When I use VInterpTo I don’t know how it works. I think I set a start point, an end point, a delta (???) and a speed. Then, the method returns a value. Here it comes my problem, how can I use this method? Maybe, the method split the distance between the end and the start point using delta and speed, and I have to call it several times until start is equal to end point. And, in the process I have to use the returned value of the method as the new start point in the next call.

Is this correct?

Thanks!

1 Like

I can answer it in blueprint, it’s basically the same.

You have to call the interp nodes on tick. So yes, the keep ‘slicing’ the values until you end up at the destination.

Like so

The important things are

  1. The Current param should be a live sample

  2. Target should be fixed

  3. Delta time needs to be connected

1 Like

Here’s the implementation of VInterpTo in Engine

CORE_API FVector FMath::VInterpTo( const FVector& Current, const FVector& Target, float DeltaTime, float InterpSpeed )
{
	// If no interp speed, jump to target value
	if( InterpSpeed <= 0.f )
	{
		return Target;
	}

	// Distance to reach
	const FVector Dist = Target - Current;

	// If distance is too small, just set the desired location
	if( Dist.SizeSquared() < UE_KINDA_SMALL_NUMBER )
	{
		return Target;
	}

	// Delta Move, Clamp so we do not over shoot.
	const FVector	DeltaMove = Dist * FMath::Clamp<float>(DeltaTime * InterpSpeed, 0.f, 1.f);

	return Current + DeltaMove;
}

It first gets the distance between the two vectors. Then multiplies that Distance with Speed and DeltaTime. Then adds it the Current vector and returns that.

1 Like

Thanks!

What’s Delta Time? And why should I use it?

1 Like

Delta time is how long each frame is taking.

You need it, because that’s how the node works. It gets called every frame :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.