๐ŸŽฎController

In this section you will find out more about the demo scripts.

The demo project heavily relies on these 3 components:

  • FPSController

  • FPSMovement

  • FPSItem/Weapon

FPSController

This class is responsible for updating user input for the animation system, changing weapons and calling callbacks on the currently equipped item.

The controller iteself does not implement reloading or firing logic, instead, such features are implemented in the FPSItem class. You can create custom entities derived directly from the FPSItem and override all the important functionality to fit your needs.

Now let's take a look at the FPSController's inspector:

FPSController inspector.

The component does not contain the data itself, instead, it uses an FPSControllerSettings asset. To create such an asset, right click and go to Create -> FPS Animator demo -> FPSControllerSettings:

Controller settings.

Specfiy the Rig Asset, as we will use it to select bones in the Weapon section. Select the asset we created previously in the Character Rig section.

Unarmed Profile: this profile will be used when toggling the unarmed state.

Turn In Place Angle: if player exceeds this value, a turn will be performed.

Turn Curve: defines how the turn will be applied.

Turn Speed: the playback of the turning animation.

As the demo project leverages Unity New Input System, you can find an Input Action asset in the Assets/Demo/Settings folder:

PlayerControls.

It already has all the important actions, and you can customize it according to your project needs.

FPSMovement

This script translates the character, controls its speed, pose and movement state:

Movement component.

Make sure to specify the Movement Settings - they define the speed of each state, smoothing and other locomotion settings:

Movement settings.

Idle/Prone/Crouching/Walking/Sprinting are movement states, which only contain the velocity and velocity smoothing properties.

Crouch Ratio will be multiplied by the player's standing height. For example, if set to 0.5 the player's height will be decreased twice when crouching.

Air Friction defines how controllable our player is when in the air. 1 means 100% controlled, and 0 means no movement input is applied.

Air Velocity defines the movement speed multiplier when in air.

Max Fall Velocity defines the max vertical velocity.

Slide Curve is a delta curve, applied when sliding.

Slide Direction Smoothing controls the rotation smoothing when sliding.

Slide Speed controls the general velocity when sliding.

Last updated