How use AddInputVector or AddMovementInput with a Pawn?

Hi everybody,
I’m new with the UE4, and I’m following some tutorial about the movement. In this moment, I’m just trying to move around a room, using a Pawn, in a fps style movement.
I know that I could use the CharacterPawn, that just handle axis input, and yes, I’ve tried and it works.

But when I try to use just the pawn and handle myself the movement, I’m just stucked and I don’t understand why.
I’m trying two different ways:
in the first, I’m using the AddInputMovement:

void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	const float ForwardValue = GetInputAxisValue("MoveX");
	const float RightValue = GetInputAxisValue("MoveY");
	const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.0f).GetClampedToMaxSize(1.f);
	const FVector Movement = MoveDirection * 5.0f * DeltaTime;
	UE_LOG(LogTemp, Warning, TEXT("%s"), *Movement.ToString())

	if (Movement.SizeSquared() >0)
	{
		PawnMovement->AddInputVector(Movement);
	}

}

But It’s not working. The Log show me that the Movement vector handle the input correctly, but AddInputVector just doesn’t work in anyway.
Same problem with the AddMovementInput

void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	const float ForwardValue = GetInputAxisValue("MoveX");
	const float RightValue = GetInputAxisValue("MoveY");
	if (ForwardValue != 0)
	{
		AddMovementInput(GetActorForwardVector(), ForwardValue);
	}

	if (RightValue != 0)
	{
		AddMovementInput(GetActorRightVector(), RightValue);
	}

}

I’ve also implemented the UPawnMovementComponent.
So, where is my misundertanding?

I’m exactly in the same situation. Would like to know what actually triggers the UpdatedComponent to move. Calling to AddInputVector in UPawnMovementComponent seems like just updates the APawn::Internal_AddMovementInput. Please help.

Hi,

The issue that you guys are facing is with the Pawn base class itself. Pawn base classes don’t have any movement algorithm implemented in them. Even though none of them are actually an interface, but you can still think of them as one. They hold the signatures functions for their children classes to implement and call. In fact, if you read the comment for AddMovementInput() function in the engine source code, you will see that it says “Base pawn classes won’t apply movement automatically and it is up to the user to do so in the tick component”. How would you implement movement? You will need to update the bone positions, actor location, rotation, etc. In short, it’s a lot of work to get a character moving. Unless you have no other choice, I suggest you guys not making your life any harder and instead, taking full advantage of what this awesome engine already equips you with :slight_smile: If you want a character that stands on two legs, start with Character class as your base class (Or even easier go with ThirdPersonCharacter project for C++). If you want a pawn that floats/flies, then go with FloatingPawnMovement component or Flying Template. However, if you can’t find the specific base movement you want and have no other choice but to implement your own pawn movement, then I suggest you guys start with this official tutorial here.

Hope this answered your questions.

Best,

Ahmad Jamialahmadi

Ok, I’ve found that we’re missing one important thing:

AddInputVector(Direction);
SafeMoveUpdatedComponent(ConsumeInputVector(), UpdatedComponent->GetComponentQuat(), true, OutHit);