VlerpTo

Hi all, bit of a newbie question here. I want to use a FMath::VInterpTo to move actor from point A to point B. The thing is I dont want to do this to be in the tick function but rather a static function I can expose as a blueprint node.

I’ve tried using a while loop but the deltatime will not change for the VInterpTo how would I write this. A the moment I have the following.


while (Pawn->GetActorLocation().FVector::Equals(NewLocation, 200.f) == false)
{
FVector locationNow = FMath::VInterpTo(Pawn->GetActorLocation(), NewLocation, World->GetDeltaSeconds(), 7.0f);

Pawn->SetActorLocation(locationNow, false);

}

A while loop doesn’t make sense here because the loop will block everything else from happening until the interpolation is complete, so it will just look like the object “snaps” to the target position anyway. Loops don’t run in parallel.

Also, the loop will get stuck forever because NewLocation is never being updated to anything.

The Lerp and VInterpTo functions are already exposed to Blueprint - the VInterp is designed to be used over a period of several frames, which is why you typically call them from tick and why the VInterp functions take a delta time. You can call them from a timer I guess, but they won’t neccesarily be called at even intervals and you’ll get stepping.

Makes sense. So how would you move an actor smoothly without using the tick function. In blueprint I’d use a gate with a delay node.

How would this be replicated in code?

I guess you have to use the tick function for stuff like this.

In blueprints you could use a Timeline node. They’re quite a lot better than tick nodes for simple procedural animation. That sounds like it’d be difficult in C++ though.

Out of interest, why would you not use Tick? This is exactly what it’s meant for.

You mean me? Because for what Timeline nodes do they’re more convenient than tick nodes.

In C++ you’d just use a tick function though, since C++ doesn’t have execution pins.

OK thanks guys I’ll use the tick function on my class. Just wanted to be sure there wasnt a better way in code for performance.

I meant OP :slight_smile: A timeline would work also yeah, but since it’s for movement I’m not sure that’s what they want… not sure. Timelines in C++ are wierd anyway, they’re best used in BP IMO.

Ticking an actor costs very little on it’s own - it’s what you do in the tick that matters. This is exactly the kind of thing it’s meant for. Even timelines are ticking actor components under the hood.

Tick being the source of ‘bad performance’ is a silly myth that seems to have taken root.