I was wondering if anyone knew the best way to move a Pawn in the following scenario:
Pawn - not Character
A server (not UE server) sends the
X,Y,Z location of the Pawn every
second
The Pawn should then smoothly update
(move to) the latest position from
the server
What I tried that worked the best was using AddMovementInput but that requires a movement vector, not a position. Is there a way to get the input vector from 2 location vectors? Say I have where the Pawn is currently, and where I need to go, can I make a Vector out of those two to supply to AddMovementInput? Or is there a better alternative?
Subtracting two vectors V2 - V1 gives you a vector from V1 to V2. Normalize that vector to make it a unit vector (length=1), and you can use that as movement input.
AddMovementInput works with a world direction so you don’t even need to convert it to local space. Something like this should do the trick :
FVector V = TargetLocation - Pawn->GetActorLocation();
FVector WorldDir = V.GetSafeNormal(); // use GetSafeNormal2D if your pawn cannot fly
Pawn->AddMovementInput(WorldDir);