AActor::AddActorLocalOffset vs APawn::AddMovementInput

In this lecture Stephen uses AddActorLocalOffset to change the movement vector of the Tank each frame, but I’ve been trying to implement the same behaviour with the new Enhanced Input plugin and, in the video I used as reference, they use AddMovementInput in it’s place. So to me it seems like they do very similar things. Could anyone tell me when I should use each one or what’s the difference between them?

Also, the Tank actually moves with AddActorLocalOffset but it doesn’t with AddMovementInput, even though the inputs are the same. Maybe I did something wrong with how I use it? This is the current snippet of code in my project. The commented part is what I tried to do with AddMovementInput that sadly does not seem to work.

void ATank::EnhancedMove(const FInputActionValue &Value)
{
	if (Value.GetMagnitude() != 0.0f)
	{
		// From Stephen's lecture, it works:
		FVector DeltaLocation = FVector::ZeroVector;
		DeltaLocation.X = Value[1];
		DeltaLocation.Y = Value[0];
		AddActorLocalOffset(DeltaLocation);

		/* From another video, it doesn't work:
		AddMovementInput(GetActorForwardVector(), Value[1]);
		AddMovementInput(GetActorRightVector(), Value[0]);
		*/
	}
}
1 Like

AddMovementInput defers to the movement component. APawn’s do not have a movement component so that does nothing. On the other hand ACharacter’s do come with one with lots of settings you can tweak like max walkspeed, movement control while airborne, etc. and is already setup for multiplayer.

If you wanted to get AddMovementInput to work with your tank then you would need to implement a movement component yourself which is non-trivial - just take a look at the UCharacterMovementComponent.

AddActorLocalOffset just moves the actor by some offset, regardless of things mentioned above.

3 Likes

Thanks for the detailed answer DanM!! :smiley:

By the way I do recommend the video I linked earlier if anyone wants to use the new input system, as the old one is considered deprecated in Unreal Engine 5.1. Remember to use AddActorLocalOffset though!

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

Privacy & Terms