๐ฎController
In this section you will find out more about the demo scripts.
Last updated
In this section you will find out more about the demo scripts.
Last updated
The demo project heavily relies on these 3 components:
FPSController
FPSMovement
FPSItem/Weapon
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:
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.
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:
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:
It already has all the important actions, and you can customize it according to your project needs.
Note 2024-04-26: the turn-in-place feature has been recently disabled in the demo project. A completely new system is coming soon.
This script translates the character, controls its speed, pose and movement state:
Make sure to specify the Movement Settings - they define the speed of each state, smoothing and other locomotion 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.