Mouse Axis physics?

Say we have an input axis MyAxis that is bound to “Mouse Axis X”, and we bind that to a function:

void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    /*...*/
    PlayerInputComponent->BindAxis(FName("MyAxis"), this, &AMyPawn::OnMyAxis);
}

void AMyPawn::OnMyAxis(float Value) {
    /*...*/
}

then while you move the mouse rightward this function will be called with positive values, while you move it leftward it will be called with negative values. While it is stationary it will have zero values. (So clearly at least the sign of Value is the same as the sign of the physical mouse velocity).

My question is about the magnitude of the value.

Are the values passed to OnMyAxis adjusted for time?

That is, if I move the mouse to the right at a constant velocity, will the values passed to this function remain constant, even if the tick rate varies? (Asking another way, is the Value proportional to the mouses physical speed?)

Or do these values need to be adjusted for DeltaTime ? That is, will the total of all the values passed to OnMyAxis each second remain constant?

Or both? Or neither?

Mouse movement is automatically adjusted for delta time because it takes time to physically move the mouse. So it doesn’t matter how many fps you have, because at the constant speed, the mouse will travel the same distance over a second, and this value is divided by the number of fps you have.

But when you use a gamepad analogue sticks, that’s different. It provides the same value every tick, so it has to be manually adjusted for fps.

With the mouse, you’re fine.

1 Like

So I think what you’re saying is that if we have an accumulator like so:

float Total = 0;

void AMyPawn::OnMyAxis(float Value) {
   Total += Value;
}

then (1) we would expect that Total would remain proportional to the physical mouse displacement (along the rightward direction) from its initial position, and (2) that the proportion would remain constant regardless of tick rate.

(I guess we could put a short sleep in Tick to test this theory.)

With mouse, yes, it will be about the same adjusted for float errors, but in most cases that’s negligible.