Download

Mouse Movement not recognized

Hello Everyone,

I am having some trouble getting Mouse Input working. I started with the Top Down Template and wanted to play around with camera movement a bit. First I added this to my PlayerController::SetupInputComponent:


InputComponent->BindAxis("DoRotationX", this, &AMyProjectPlayerController::RotateCameraX);
InputComponent->BindAxis("DoRotationY", this, &AMyProjectPlayerController::RotateCameraY);

Then I addded my two methods:


void AMyProjectPlayerController::RotateCameraX(float Value)
{

}


void AMyProjectPlayerController::RotateCameraY(float Value)
{
	AMyProjectCharacter* Player = Cast<AMyProjectCharacter>(GetPawn());
	if (Player && Value != 0.0f)
	{
		USpringArmComponent *Arm = Player->CameraBoom;
		FRotator Rot(0.0f, Value * GetWorld()->GetDeltaSeconds(), 0.0f);
		Arm->AddRelativeRotation(Rot);
	}
}

The third step was to add the input in the editor. So I did this and added a Axis Input. One with Mouse Y and one with Mouse X.

Now when I run the Game, and I set a breakpoint in the function RotateCameraY, i NEVER get a value for Value > 0.0f. Its always 0.0f. Doesn’t matter how fast I move the mouse. Is there anything blocking my input ?

Any help is very appreciated.

Gr.
Markus

Did you try to debug those value, see if it’s even passing in your functions ?

you can see how to print / log here : https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime

Yes, the two methods get called repeatedly. But only with a Value of 0.0f. Thus if I set a breakpoint within the if statement, it will never get triggered.

In your DeaultInput file (C:\Users\username\Documents\Unreal Projects\GameTest\Config), you should have some lines that resembles something like:

-AxisConfig=(AxisKeyName=“MouseY”,AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f))

+AxisMappings=(AxisName=“DoRotationY”,Key=MouseY,Scale=1.000000)

This will make sure your mouse is setup as an axis and then your DoRotationY will be picked up correctly by your SetupInputComponent. Also, is this on a character class and is the SetupInputComponent being overridden in the header?

Hi Dune, the function works now. It had indeed to do with my Mapping AxisName. I had a typo there. There is now another issue: It doesn’t work if I don’t hold the left/right mousebutton. Unfortunately when I keep the left or right mouse button pressed, then the movement will get triggered.

Any ideas?