First-Person Controller
A basic character controller based on Unity's Character Controller
Last updated
A basic character controller based on Unity's Character Controller
Last updated
The first-person controller in the FPS Framework is based on the character controller, which gives a lot of control over the character without any external physics behaviors.
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:
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
On jump
Gets invoked when jumping
On land
Gets invoked when landing
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.
For more information about the audio system, see this.
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.
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 here.
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:
Now add a comma next to your class name then add ICharacterController like this:
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.
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:
Now the methods:
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:
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:
Save and go back to the editor, now create a new FPS Controller and drag the entire Camera object from the new FPS Controller to your custom FPS Controller like this:
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.