Download

c++ FMath::abs and FVector::dist

Hello,
I am using a line of code to move an AI character to a location based on MoveToLocation with Fvector
i am trying reset this when i am getting to the position but i have found that this line


float distance = FMath::Abs(FVector::Dist(nextWayPoint, GetPawn()->GetActorLocation()));

The lowest value of distance will be a bit over 263 and not 0.
My question is why that happens and if there is a better approach to the subject.

Distances are always positive so that call to Abs is superfluous.

It’s impossible to say why the distance is never zero, but the obvious answer is that the actor location is not perfectly at the location of “nextWayPoint”

So move to location doesn’t move the actor to the spot only close by?

Yes, there’s a tolerance radius that you should set to somewhere between 10 and 10000, depending on what you’re doing. Keep in mind that tiny tiny waypoint goals mean your character will do weird stuff when it gets there, like spin around a fair bit getting exactly on it.