Move a pawn to a location using UPawnMovementComponent

I’ve just started to learn Unreal Engine 4.26.2.

I want to move a pawn from its location to another one. If I get a FVector with the destination, what do I have to do to move the pawn?

I have a class that inherits from UPawnMovementComponent where I have implemented the method:

virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

Do I have to pass the destination to the method AddInputVector?

I don’t know if I have to compute another vector using my current location and the destination location.

You would give it a ‘unit vector’ that points from your current location to the destination.

(Destination - GetActorLocation()).GetSafeNormal()
1 Like

Yes, Normalize is the same as GetSafeNormal.

What do you mean “it still flies to me”? I dont understand.

Also, in your blueprint, you did (PawnLocation - Destination)
you should switch those 2 pins so its (Destination - PawnLocation)

Sorry, I messed two different questions.

I’m going to remove the blueprint answer.

Do you want to teleport the actor or move it over time? If you want to teleport it, there’s a teleport function or you could use set actor location (both of those should be done on server (optionally with local client prediction) and will cause net corrections if you’re doing multiplayer).

If you want to move somewhere over time and you’re OK with the default movement behavior, you could probably use add input vector.

As mentioned, you’d want to get a normal vector (destination vector minus location vector then normalized) to pass in to add input vector. And you’ll have to call add input vector that way each frame until the pawn has arrived at its location. If it’s not moving at a good speed, you can adjust it’s maxspeed variable.

1 Like

But, I think that UPawnMovementComponent doesn’t have a public MaxSpeed variable. Or maybe I’m wrong.

1 Like

Ah - yup, I was thinking of the CharacterMovementComponent. Is there a reason you’re using the PawnMovementComponent instead of the CharacterMovementComponent?

1 Like

Yes, the quote above and also because I’m moving a Pawn not a Character.