How to normalize movement

Hello Community,
I am programming a simple top down shooter in C++ using the Unreal Engine.
Everyting is working as expected and perfectly, except for one thing:
I am using a Player Controller to move the Pawn throw the World. The Problem is that when i press A (Walk Left) and W (walk forward) at the same time my charackter is way faster than just pressing a single Button.

// Input for Forward and Backward
void APlayerCharackterController::MoveForwardAndBackward(float Value)
{
if (Value != 0.0f)
{
APawn* const PlayerCharackterPawn = GetPawn();
PlayerCharackterPawn->AddMovementInput(GetActorForwardVector(), Value);
}
}

// Input for Right and Left
void APlayerCharackterController::MoveRightAndLeft(float Value)
{
if (Value != 0.0f)
{
// add movement in that direction
APawn* const PlayerCharackterPawn = GetPawn();
PlayerCharackterPawn->AddMovementInput(GetActorRightVector(), Value);
}
}

So, I am pretty sure why this problem is there, but I have no Idea how I can solve this problem. I thought about normalizing a Vector, but, as I alredy said, i have no Solution to this problem.
I just want to move the Pawn in the same speed when i press one or two buttons.

Thank you in advance for yout help

ps: sorry for my bad english :wink:

Hi,

Dont move your charater on Key event. In key events juste set a boolean that say if player is pressing button.

Then in the Tick function of your charater, you test all boolean for all directions. You decide the direction to take and move your charater in that direction.

Don’t forget to multiple le Velocity value with DeltaTime to not be Frame dependends

Thank you very much!
I will try it out as soon as possible :wink: