# Controller

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.&#x20;

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:

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2F2akmIoVE3QdQriwFU5k7%2Fimage.png?alt=media&#x26;token=cd8afb8b-b138-4c5f-a7f8-96281c83c4e3" alt="" width="416"><figcaption><p>FPSController inspector.</p></figcaption></figure>

{% hint style="success" %}
**Tip:** make sure to add the component to the character root game object. This scripts manually rotates character for turn-in-place feature, so it is crucial that the whole player is rotated.
{% endhint %}

The component does not contain the data itself, instead, it uses an FPSControllerSettings asset. To create such an asset, right click and go to <mark style="background-color:purple;">**Create -> FPS Animator demo -> FPSControllerSettings:**</mark>

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FlMOCvTi9bLEVos3dcfaA%2Fimage.png?alt=media&#x26;token=382c2a5b-a64f-4b60-b461-3bd0c816d505" alt="" width="374"><figcaption><p>Controller settings.</p></figcaption></figure>

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](https://kinemation.gitbook.io/scriptable-animation-system/workflow/character-rig "mention") section.

{% tabs %}
{% tab title="Animation" %}
**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.&#x20;

**Turn Speed:** the playback of the turning animation.
{% endtab %}

{% tab title="Controller" %}
**Time Scale:** controls the real time scale.

**Equip Delay:** defines the delay time for the next weapon to be equipped.

**Lean Angle:** the max leaning angle in degrees.

**Sensitivity:** mouse input sensitivity scale.
{% endtab %}

{% tab title="Weapon" %}
**WeaponBone**: all weapons will be parented to this element. Just select the IK WeaponBone here.

**Prefabs:** defines all the weapon prefabs the system will spawn when the game starts.
{% endtab %}
{% endtabs %}

As the demo project leverages Unity New Input System, you can find an Input Action asset in the <mark style="background-color:purple;">**Assets/Demo/Settings**</mark> folder:

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FbvszP2nu7crI6q91ZcSF%2Fimage.png?alt=media&#x26;token=7873da01-87e8-43da-8400-0176eba7f005" alt="" width="226"><figcaption><p>PlayerControls.</p></figcaption></figure>

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

{% hint style="danger" %}
**Note 2024-04-26:** the turn-in-place feature has been recently disabled in the demo project. A completely new system is coming soon.
{% endhint %}

## FPSMovement

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

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FNlkBnERFmYZxWKsUeA2f%2Fimage.png?alt=media&#x26;token=4d828b45-3a3b-460d-a611-08a38ab7dec3" alt="" width="381"><figcaption><p>Movement component.</p></figcaption></figure>

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

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FCz4hE839Uga404r5kBFU%2Fimage.png?alt=media&#x26;token=562be5c4-2af7-43c9-8ba3-6a50a25dffe4" alt="" width="380"><figcaption><p>Movement settings.</p></figcaption></figure>

**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.
