Axis Mappings – normalized input

If you've noticed, inputs of 1.0 right and 1.0 forward will actually sum to a total of 2.0 units of speed. This means it is possible to move faster diagonally than it is to move in purely forward, backward, left, or right directions. What we really should do is clamp off any input value that results in speed in excess of 1.0 units while maintaining the direction of input indicated. We can do this by storing the previous input values, and overriding the ::Tick() function.

Getting ready

Open a project, and set up a Character derivative class (let's call ours Warrior).

How to do it…

  1. Override the AWarrior::SetupPlayerInputComponent( UInputComponent* Input ) function as follows:
    void AWarrior::SetupPlayerInputComponent( ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.