AddControllerYawInput is adding undesired movement

Hello,

I have an ALPlayerController class that inherits from APlayerController, in which I am doing the usual input actions such as moving the character forward, strafing and turning (by calling AddControllerYawInput).

Thing is, I also wanted to set it so that if both the two mouse buttons were pressed at the same time, it would be equivalent to moving forward. The way I did it was setting two booleans and checking them in the Tick function, and it works fine, but…

When I press the two mouth buttons + S, the character doesn’t move (works fine), but when i also press the A or D key to turn, it suddenly gets moving instead of just turning while staying still. In fact, the resulting movement is pretty much equivalent to moving forward + turning, but with a different orientation. Supposedly the forward and backward movement gets zeroed as they are opposed, why is there any movement when i call the AddControllerYawInput() ??

Note: The Acceleration displayed in the Tick() function is not zero when this happens.

The code for the controller:

#include "Lynaeorium.h"
#include "LPlayerController.h"
#include <Lynaeorium/Components/NewPlayerMovement.h>


ALPlayerController::ALPlayerController()
{
	bCameraFreeLookOn, bCameraRotationOn = false;
}


void ALPlayerController::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	if (bCameraRotationOn && bCameraFreeLookOn) 
		GetPawn()->AddMovementInput(GetPawn()->GetActorForwardVector(), 1.f);

	if (GEngine) GEngine->AddOnScreenDebugMessage(0, 2.f, FColor::Magenta, GetCharacter()->GetCharacterMovement()->GetCurrentAcceleration().ToString());
}


void ALPlayerController::ActivateCameraFreeLook()
{
	bCameraFreeLookOn = true;
}


void ALPlayerController::DeactivateCameraFreeLook()
{
	bCameraFreeLookOn = false;
}


void ALPlayerController::ActivateCameraRotation()
{
	bCameraRotationOn = true;
}


void ALPlayerController::DeactivateCameraRotation()
{
	bCameraRotationOn = false;
}


void ALPlayerController::Jump()
{
	if (PlayerMovementIsValid()) PlayerMovement->SetJump();
}


void ALPlayerController::SetForwardMovement(float AxisValue)
{
	GetPawn()->AddMovementInput(GetPawn()->GetActorForwardVector(), AxisValue);
}


void ALPlayerController::SetStrafeMovement(float AxisValue)
{
	GetPawn()->AddMovementInput(GetPawn()->GetActorRightVector(), AxisValue);
}


void ALPlayerController::SetTurnMovement(float AxisValue)
{
	GetPawn()->AddControllerYawInput(FMath::Clamp(AxisValue, -1.f, 1.f));
}


bool ALPlayerController::PlayerMovementIsValid()
{
	if (PlayerMovement) return true;

	PlayerMovement = Cast<UNewPlayerMovement>(GetCharacter()->GetCharacterMovement());
	return PlayerMovement ? true : false;
}


void ALPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	InputComponent->BindAction("CameraFreeLook", IE_Pressed, this, &ALPlayerController::ActivateCameraFreeLook);
	InputComponent->BindAction("CameraFreeLook", IE_Released, this, &ALPlayerController::DeactivateCameraFreeLook);
	InputComponent->BindAction("CameraRotation", IE_Pressed, this, &ALPlayerController::ActivateCameraRotation);
	InputComponent->BindAction("CameraRotation", IE_Released, this, &ALPlayerController::DeactivateCameraRotation);
	InputComponent->BindAction("Jump", IE_Pressed, this, &ALPlayerController::Jump);

	InputComponent->BindAxis("Forward", this, &ALPlayerController::SetForwardMovement);
	InputComponent->BindAxis("Strafe", this, &ALPlayerController::SetStrafeMovement);
	InputComponent->BindAxis("Turn", this, &ALPlayerController::SetTurnMovement);
}

This problem has to deal with the AddMovementInput() being called in the Tick function. I tested removing it, and checking the pressed mouse buttons in a function binded to an Axis, which turned out to work fine.

I found a workaround:
Having an Axis Mapping for the RightMouseButton, checking both mouse buttons there and applying the movement inside it. But this is pretty dirty and will probably bring some problems if I try doing other things with the mouse buttons.

Is there a function that gets called every time the Axis Mappings are checked, without the need to have a key pressed?

I found the function that gets called for the Axis readings, which is in the PlayerController.h file and protected:

virtual void ProcessPlayerInput(const float DeltaTime, const bool bGamePaused);

So I overrided it and set it up in the cpp, and now everything works as intended! I’ll leave the answer in case someone runs into this same problem.

Here is the overrided function:

void ALPlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused)
{
	Super::ProcessPlayerInput(DeltaTime, bGamePaused);

	if (bCameraRotationOn && bCameraFreeLookOn)
		GetPawn()->AddMovementInput(GetPawn()->GetActorForwardVector(), 1.f);
}

Had a similar problem. thx