# First-Person Controller

The first-person controller in the FPS Framework is based on the [character controller,](https://docs.unity3d.com/ScriptReference/CharacterController.html) which gives a lot of control over the character without any external physics behaviors.

## Creating a first person controller

The FPS Framework has a lot of creators; these creators are responsible for creating things like Weapons, characters, and UI. To access the FPS creator, right-click on the hierarchy. This will show a menu. Click on the menu **Akila,** **FPS Framework,** then **FPS Controller,** like this:

<div align="left"><figure><img src="/files/LRuPQSP3TeVU8ywwMu44" alt=""><figcaption><p>Creating a new FPS Controller</p></figcaption></figure></div>

After clicking on **FPS Controller,** you should have a functional first-person controller in your scene. The character has a camera by default; if your scene already has a camera, delete it.

Now this is what you should see:

<div align="left"><figure><img src="/files/XMpw6oZ0xkatNwL1JPyM" alt=""><figcaption><p>Created a new FPS Controller</p></figcaption></figure></div>

### Fields

<table><thead><tr><th width="233">Name</th><th>Description</th></tr></thead><tbody><tr><td>Acceleration</td><td>The start and stop movement speed. The higher the value is the slower the character will start moving and stop.</td></tr><tr><td>Walk speed</td><td>The speed of the character while walking. The higher the value is the faster the character will move.</td></tr><tr><td>Sprint speed</td><td>The speed of the character while sprinting.The higher the value is the faster the character will move.</td></tr><tr><td>Tactical sprint speed</td><td>The speed of the character while sprinting tactical sprint.The higher the value is the faster the character will move</td></tr><tr><td>Jump height</td><td>How high the character can jump. The higher the value is the higher the jump is.</td></tr><tr><td>Crouch height</td><td>How low the character can crouch. The higher value is the less the character will lower itself.</td></tr><tr><td>Crouch Time</td><td>Time taken to perform crouching in and out.</td></tr><tr><td>Walking Step Interval</td><td>How fast are the character steps during walking (This doesn't affect movement speed but the sounds). The higher the value is the faster the character will step his steps.</td></tr><tr><td>Sprinting Step interval</td><td>How fast are the character steps during sprinting (This doesn't affect movement speed but the sounds). The higher the value is the faster the character will step his steps.</td></tr><tr><td>Preserve Momentum</td><td>If true, maintains horizontal momentum when jumping or falling.</td></tr><tr><td>Slide down slopes</td><td>If true the character will slide down when on slope with a height angle than CharacterController.slopeAngle.</td></tr><tr><td>Slope slide speed</td><td>How fast the character will accelerate on slopes. The higher the value is the faster the slide will be.</td></tr><tr><td>Gravity</td><td>A multiplier for the gravity of the character. This is Physics.gravity * gravity</td></tr><tr><td>Max fall speed</td><td>Max falling speed in Km/h</td></tr><tr><td>Stick to ground force</td><td>The force applied to the character when on ground or slope, the higher the value the lower jumping is and </td></tr><tr><td>Camera</td><td>The camera or camera holder that the character should move when rotating view.</td></tr><tr><td>Sensitivity</td><td>How sensitive the view rotation is to the input.</td></tr><tr><td>Maximum X</td><td>Max angle that the view can reach.</td></tr><tr><td>Minimum X</td><td>Min angle that the view can reach.</td></tr><tr><td>Dynamic sensitivity</td><td>If true the sensitivity will change with the field of view and will keep the same feeling.</td></tr><tr><td>Lock cursor</td><td>If true the cursor will be invisible and locked on start</td></tr><tr><td>Global orientation</td><td>If true the orientation will be global meaning the rotation of the character itself won't affect the character view.</td></tr><tr><td>Footsteps SFX</td><td>A list of audio profiles that plays when a step happens.</td></tr><tr><td>Jump SFX</td><td>An audio profile that plays when jumping</td></tr><tr><td>Land SFX</td><td>An audio profile that plays when landing</td></tr></tbody></table>

### Events

<table><thead><tr><th width="155">Name</th><th>Description</th></tr></thead><tbody><tr><td>On jump</td><td>Gets invoked when jumping</td></tr><tr><td>On land</td><td>Gets invoked when landing</td></tr></tbody></table>

### Adding sounds

The only thing missing now is the audio. To add audio, click on the first-person controller object you just created and assign the sound to its fields. The sounds are not audio clips but audio profiles, but what's an audio profile?

The framework has a dedicated audio system that manages playing sounds better than the default methods, and this audio system uses audio profiles to do its work. If you want to create an audio profile and assign it, right-click on the project window and hover your mouse cursor over the menu **Create,** then click on the item **Audio Profile** like this:

<div align="left"><figure><img src="/files/eKpyDVFhpnT5kZBnpCZB" alt=""><figcaption><p>Creating an audio profile</p></figcaption></figure></div>

Now assign the audio clip inside of your new Audio Profile and assign the new audio profile to the appropriate sound effect field in the First Person Controller component.

For more information about the audio system, see [this](/fps-framework/tutorials/systems/audio-system.md).

### Moving platforms

By default the character controller doesn't move with any moving platforms. To fix this, add the component "Speedometer" to the desired platform (e.g car, train etc..).&#x20;

{% hint style="info" %}
Detecting and moving with moving platform could be automated via the `Auto Detect Moving Platforms` from the FirstPersonController component.
{% endhint %}

## Supporting custom controllers

{% hint style="success" %}
The following steps apply to any type of FPS controller whether it’s CharacterController-based, Rigidbody-based, or kinematic. Review how each step fits your custom classes and implement them accordingly.
{% endhint %}

The **ICharacterController** uses an interface to communicate with other systems. By implementing this interface, integration should work automatically.

Understanding how the system works in a unified environment is essential. Therefore, it’s highly recommended to use Unity’s **Standard Assets FPS Controller** while following along, ensuring no external factors affect the integration. You can download and import the `.unitypackage` from [this link.](https://discord.com/channels/981086478128017448/1131568098550485102)

The integration is handled through several components, including the **Character Manager**, **Input Manager**, and an interface called **ICharacterController**. Let’s begin by adding these components to your custom character controller object, as shown below:

<div align="left"><figure><img src="/files/PVehLMT6ARC1FRfOB42G" alt="" width="563"><figcaption></figcaption></figure></div>

Use Akila.FPSFramework namespace to get access to all FPSF's code base.

```csharp
using Akila.FPSFramework;

public class FPSController : MonoBehaviour
```

Implement ICharacterController interface as shown below.

```csharp
using Akila.FPSFramework;

public class FPSController : MonoBehaviour, ICharacterController
```

As far as this, FPSF knows about your custom movement, but it's unable to change your player speed, or invoke the events in CharacterManager class and other things like this. To fix these, the CharacterManager needs to be feed with some info in the Update() function.

In your script, refrence the CharacterManager and call SetValues() function as shown below.

```csharp
using Akila.FPSFramework;
using UnityEngine;

public class FPSController : MonoBehaviour, ICharacterController
{
    public CharacterManager characterManager;

    // Your own custom fields
    public bool isGrounded;
    public float walkSpeed;
    public float sprintSpeed;
    public Vector3 playerVelocity;

    // A value used in your custom movement class that multiplies the total velocity.
    // This value is copied from the CharacterManager to modify your custom movement speeds.
    public float speedMultiplier;

    private void Update()
    {
        // Notify the CharacterManager of the current values.
        // It can then trigger events and update other scripts accordingly.
        characterManager.SetValues(playerVelocity, isGrounded, walkSpeed, sprintSpeed);
    
        //Copy the value from CharacterManager since other classes change this value
        // This float is used to modify the movement speed for example, when aiming.
        speedMultiplier = characterManager.speedMultiplier;
    }
}

```

The scripting is done, only thing missing now is to use FPSF's built-in components with your custom FPSController. To speed this up, [create a new FPS Controller ](/fps-framework/tutorials/character/first-person-controller.md#creating-a-first-person-controller)and  drag the entire Camera object from the new FPS Controller to your custom FPS Controller like this:

<div align="left"><figure><img src="/files/atBoLVXvgkv0jW8gRxuo" alt=""><figcaption><p>The custom FPS Controller with the entire Camera object</p></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://akila.gitbook.io/fps-framework/tutorials/character/first-person-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
