How to properly deal with diagonal pawn movement?

Hey! I’ve a very simple question I think, and I’d appreciate any help! :slight_smile:
Basiclly, my player is moving faster when it moves in diagonal, I’ve readen in other posts that normalize is what I need. But I don’t know how to modify my code to do it…
Thank you so much! This is the code:

void AMyCharacter::MoveForward(float axisValue)
{
	const FVector direction = GetActorForwardVector();
	AddMovementInput(direction, playerSpeed*axisValue);
}

void AMyCharacter::MoveRight(float axisValue)
{
	const FVector direction = GetActorRightVector();
	AddMovementInput(direction, playerSpeed*axisValue);
}

// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	PlayerInputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward);
	PlayerInputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight);

}

Before looking into normalization, have you tried removing playerSpeed from the addMovementInput call? I think that may cause weird results since your velocity will be 0 when the character is idling.

Here’s a link to another forum post on normalizing.
Normalize vector

Clamping might be worth looking into as well.
Clamp

1 Like