⚙️
FPS Framework
Asset StoreFab
  • Get Started
    • Welcome!
    • Setup
  • Tutorials
    • Character
      • First-Person Controller
      • Inventory
      • Firearm
        • Basics
        • Advanced
        • Other
          • Spray pattern
          • Attachment System
          • Projectile System
      • Explosive
    • Systems
      • Audio System
      • Animation System
      • Interactions
        • Pickable
      • Save System
      • Settings System
    • Tools
      • Extension Methods
    • UI
      • FPS Counter
      • Get Name
      • Image Size Fitter
  • Other
    • Full Change Log
      • 2025 Change Log
      • 2024 Change Log
      • 2023 Change Log
      • 2022 Change Log
Powered by GitBook
On this page
  • Creating a first person controller
  • Fields
  • Events
  • Adding sounds
  • Supporting custom controllers

Was this helpful?

  1. Tutorials
  2. Character

First-Person Controller

A basic character controller based on Unity's Character Controller

PreviousCharacterNextInventory

Last updated 1 year ago

Was this helpful?

The first-person controller in the FPS Framework is based on the 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:

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:

Fields

Name
Description

Acceleration

The start and stop movement speed. The higher the value is the slower the character will start moving and stop.

Walk speed

The speed of the character while walking. The higher the value is the faster the character will move.

Sprint speed

The speed of the character while sprinting.The higher the value is the faster the character will move.

Tactical sprint speed

The speed of the character while sprinting tactical sprint.The higher the value is the faster the character will move

Jump height

How high the character can jump. The higher the value is the higher the jump is.

Crouch height

How low the character can crouch. The higher value is the less the character will lower itself.

Step interval

How fast are the character steps (This doesn't affect movement speed but the sounds). The higher the value is the faster the character will step his steps.

Slide down slopes

If true the character will slide down when on slope with a height angle than CharacterController.slopeAngle.

Slope slide speed

How fast the character will accelerate on slopes. The higher the value is the faster the slide will be.

Gravity

A multiplier for the gravity of the character. This is Physics.gravity * gravity

Max fall speed

Max falling speed in Km/h

Stick to ground force

The force applied to the character when on ground or slope, the higher the value the lower jumping is and

Camera

The camera or camera holder that the character should move when rotating view.

Sensitivity

How sensitive the view rotation is to the input.

Maximum X

Max angle that the view can reach.

Minimum X

Min angle that the view can reach.

Dynamic sensitivity

If true the sensitivity will change with the field of view and will keep the same feeling.

Lock cursor

If true the cursor will be invisible and locked on start

Global orientation

If true the orientation will be global meaning the rotation of the character itself won't affect the character view.

Footsteps SFX

A list of audio profiles that plays when a step happens.

Jump SFX

An audio profile that plays when jumping

Land SFX

An audio profile that plays when landing

Events

Name
Description

On jump

Gets invoked when jumping

On land

Gets invoked when landing

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:

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.

Supporting custom controllers

The character controller is using an interface to interact with other systems; implementing this interface should do the work for you. All you need is your custom movement system and Unity.

The integration happens using multiple components like the Character Manager, Input Manager and an interface called ICharacterController, let's' start by adding the components on your custom character controller object first like this:

Make sure to add the components above along with your custom first person controller component. Now add the namespace FPSFramework to your first person controller script like this:

using Akila.FPSFramework;

public class FPSController : MonoBehaviour

Now add a comma next to your class name then add ICharacterController like this:

using Akila.FPSFramework;

public class FPSController : MonoBehaviour, ICharacterController

Now you should see an error coming out of the interface, this is because the interface is not implemented yet, to implement it use Visual Studio's Quick Action And Refactoring by right clicking on the error and click on it. If you are using VSCode or you can't see it, copy all the properties and methods below into your first person controller class.

public float sensitivity => throw new System.NotImplementedException();

public float sprintSpeed => throw new System.NotImplementedException();

public float walkSpeed => throw new System.NotImplementedException();

public float tacticalSprintSpeed => throw new System.NotImplementedException();

public float tacticalSprintAmount => throw new System.NotImplementedException();

public bool canTacticalSprint => throw new System.NotImplementedException();

public bool MaxedCameraRotation()
{
    throw new System.NotImplementedException();
}

public void ResetSpeed()
{
    throw new System.NotImplementedException();
}

public void SetSpeed(float walkSpeed, float runSpeed, float tacticalSprintSpeed)
{
    throw new System.NotImplementedException();
}

Now that you got your interface implemented you need to return these methods and properties a value one by one, you should start with the properties first like this:

[SerializeField] float m_mouseSensitivity = 500;
[SerializeField] float m_walkSpeed = 10;
[SerializeField] float m_sprintSpeed = 10;
[SerializeField] float m_tacticalSprintSpeed = 10;

public float sensitivity => m_mouseSensitivity;
public float sprintSpeed => m_sprintSpeed;
public float walkSpeed => m_walkSpeed;
public float tacticalSprintSpeed => m_tacticalSprintSpeed;

//Input the value bettwen 0 and 1 depending on the current state.
//This is used for the tac sprint animation only, 0 is idle 1 is sprinting.
public float tacticalSprintAmount => 0;

Now the methods:

[SerializeField] float m_walkSpeed = 5;
[SerializeField] float m_sprintSpeed = 10;
[SerializeField] float m_tacticalSprintSpeed = 12;

private float xCamRotation;
private float defaultWalkSpeed = 5;
private float defaultSprintSpeed 10;
private float defaultTacticalSprintSpeed = 12;

//Used to stop weapon sway if true
public bool MaxedCameraRotation()
{
    return xCamRotation < -90 + 1 || xCamRotation > 90 - 1;
}

//Used by the firearm to set speeds when idle.
public void ResetSpeed()
{
    //You could cash the default values on start
    m_walkSpeed = defaultWalkSpeed;
    m_sprintSpeed = defaultSprintSpeed;
    m_tacticalSprintSpeed = defaultTacticalSprintSpeed;
}

//Used by the firearm to set speed depening on the current state
public void SetSpeed(float walkSpeed, float runSpeed, float tacticalSprintSpeed)
{
    m_walkSpeed = walkSpeed;
    m_sprintSpeed = runSpeed;
    m_tacticalSprintSpeed = tacticalSprintSpeed;
}

Now the setup itself. You need to call a function in the CharacterManager class called Setup(), this function is usable for character controllers and rigidbody controllers too. for character controllers you just need to call the setup function in the Awake() or the Start() and like that:

private void Start()
{
    Actor actor = GetComponent<Actor>();
    CharacterController controller = GetComponent<CharacterController>();
    CameraManager cameraManager = GetComponentInChildren<CameraManager>();
    CharacterManager characterManager = GetComponent<CharacterManager>();
    characterManager.Setup(actor, controller, cameraManager, transform);
}

Rigidbody controllers have one extra thing needed, which is updating the grounded state since the each rigidbody controller has his own method of checking for ground contact. To update the grounded state call a method in the CharacterManager called UpdateGroundedState() like this:

private void Update()
{
    //Note that is grounded is your custom bool value.
    characterManager.UpdateGroundedState(isGrounded);
}

By "The entire camera object" I meant the camera object in the FPS Framework's default FPS Controller because it contains all the required components.

For more information about the audio system, see .

To kickstart this support, I will use Unity's standard asset's FPS Controller. You can get it from the Discord server if you are verified. The character controller can be found

Save and go back to the editor, now and drag the entire Camera object from the new FPS Controller to your custom FPS Controller like this:

this
here.
create a new FPS Controller
character controller,
Creating a new FPS Controller
Created a new FPS Controller
Creating an audio profile
The required components for any character controller.
The custom FPS Controller with the entire Camera object