Move a blank pawn with WASD C++

Hi,

I’m trying to move a pawn using the WASD keys. I am using the following code:

RDDPStrategyPawn.h

UFUNCTION()
	void MoveUp(float Val);
UFUNCTION()
	void MoveRight(float Val);

RDDPStrategyPawn.ccp

void ARDDPStrategyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);
	InputComponent->BindAxis("MoveUp", this, &ARDDPStrategyPawn::MoveUp);
	InputComponent->BindAxis("MoveRight", this, &ARDDPStrategyPawn::MoveRight);

}

void ARDDPStrategyPawn::MoveUp(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		FRotator Rotation = Controller->GetControlRotation();
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
		AddMovementInput(Direction, Value);
	}
}

void ARDDPStrategyPawn::MoveRight(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		const FRotator Rotation = Controller->GetControlRotation();
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
		AddMovementInput(Direction, Value);
	}
}

It compiles and runs just fine, and works perfectly on a Character-type pawn. However, movement controls do not work when applied to a blank pawn. Am I missing something obvious?

Regards, Rob

Ehm, if i’m not mistaken, the Pawn class in comparison with the Character class lacks the MovementComponent. That’s why you can’t move the Pawn. :X

Thanks for the reply, you are right. I figured out a workaround by using the Character Class.

I’m glad i was able to help. I will mark this question as resolved. Feel free to reopen it if you have questions regarding this problem.