I don't understand exactly how axis mapping works

I’ve been reading a tutorial from the officials documentation on how to make a first person shooter character. And I stumbled upon axis mapping and mouse camera rotation.

With no explanation on how it works i’ve been given this code:

InputComponent->BindAxis("LookX", this, &AFPSCharacter::AddControllerYawInput);
 InputComponent->BindAxis("LookY", this, &AFPSCharacter::AddControllerPitchInput);

LookX and LookY are the binding I made in the compiler , LookX has a Mouse X component with Scale 1.0 and LookY has a Mouse Y component with scale -1.0

I don’t understand what scalling is doing and how AddControllerYawInput works.
Can anyone explain in detail?

see https://docs.unrealengine.com/latest/INT/Gameplay/Input/index.html.

Short summary: ActionMappings are a single keypress that is either pressed or not-pressed.

Axismappings have more granularity. Lets say you move your mouse to the left. It wouldnt help to just have an actionmapping, because then you would only know that the mouse is moved on one Axis, but you also want to know how fast it moves. This is where AxisMappings are handy. For example, if you move your mouse left fast, the AxisMapping will return -1, if you move your mouse left slow it will return something like -0.31, if you move it right slowly it will be 0.4 etc. A value of 0 will mean that it is not moved at all.

You can do similar for normal keys, lets use “A” and “D” as an example. You could do actionmappings for each key now, but that is not really great, since you have multiple nodes now. So you can define an AxisMapping named “MoveLeft”. Add the “A” key and give it a scale of “1.0”. This means that if you press “A”, the Axismapping will trigger with a value of “1.0”. Now add the “D” key with scale of “-1.0”. If you press D now, it will return “-1.0”.

You could also set the scale value to something higher. Like, set it to 5 instead of 1. Then the original value (i.e. 0.3) will be multiplied by 5 (this would give 1.5 for this example then).

The other difference is, that AxisMappings will trigger continuously each frame as long as the button is pressed. With an ActionMapping you will only get the initial press and then the release event.

The AddControllerYawInput does nothing else than telling the PlayerController to rotate his Yaw-Axis by the given Input value. The input value is usually expected to be between -1 and +1. So you can feed the output of a AxisMapping directly into the AddControllerYawInput node/function and it will rotate accordingly. Please note that for this to work, you need to have the setting “Use Controller Yaw” in the PlayerCharacter set to true (this is done by default in the engine).

Hope that helped a bit and did not confuse you even more :slight_smile: