🔷Controller setup

In this section we will add demo scripts.

Add Character and FPS Controllers

First, add the standard Character Controller:

Now we need to add a demo project script - FPSController. It handles all the gameplay actions in the project.

Turn In Place

Once you've added the FPSController, set up the Turn In Place feature first:

The Turn Curve must be in range [0;1], for both value and time:

This curve will be used to procedurally rotate the character when it's time to turn.

Smooth Leaning

Now we need to adjust the Smooth Leaning - a game mechanic, which allows to control the leaning amount with the mouse wheel:

Smooth Lean Step defines the leaning sensitivity, and Start Lean defines the initial leaning amount in percents (1 means 100%, 0 means 0%).

IK Animations/Poses

Now we need to set up the IK Animation:

IK Animation is a Scriptable Object, which is applied procedurally and used as a transitions motion for aiming, leaning, crouching and jumping events:

Rot and Loc are animation curves for each rotation/translation axis

Blend Speed defines how fast we want to blend the motion in.

Play Rate defines the speed of the motion.

Scale is a global multiplier for the motion, and it's computed randomly in range [X;Y].

Another IK feature used in the FPS Animation Framework is IK Poses. Unlike IK Animations, which are fire-and-forget type of thing, the IK Poses are mean to be used for different animation states.

For example, let's say we don't like our pose when sprinting. We can create a new IK Pose for this animation state, and simply blend it in when we start sprinting:

Pose defines the additive offset for rotation/translation, and Blend In/Out Speed defines how fast we want to blend in/out.

Controller Settings

Now let's set up the Controller tab.

Time Scale allows you to add a slow motion effect, if less than 1.

Equip Delay defines the timer length for the wepaon equip action. We don't rely on the animation events, instead we set a timer when we start equipping another weapon.

Assign Main Camera, Camera Holder and First Person Camera objects using the references from the Camera setup step. (Edit: First Person Camera is the FPCameraSocket).

Finally we have a Movement Component reference, which we will deal with in the next chapter.

Movement Component

All movement logic is handled in the FPSMovement.cs script. Add this component directly to your character and assign its reference in the FPSController/Controller tab.

Let's take at the inspector:

Use the rootBone GameObject in the skeleton hierarchy and assign it to the respective property.

Movement Settings is a Scriptable Object, which contains all the necessary settings for different movement states:

Idle, Prone, Crouching and others contain a Velocity (defines the movement speed) and Velocity Smoothing (how responsive the state should be. If zero - no smoothing applied).

Crouch Ratio is a multiplier for the capsule height when crouching.

Jump Height defines how high we want to jump.

Air Friction/Velocity represent the responsiveness and movement speed when in air.

Max Fall Velocity will be used to clamp the gravity.

Slide Curve defines how sliding will be applied.

Slide Dircetion Smoothing defines the responsiveness when sliding.

Slide Speed defines the sliding velocity.

At this point we've completeted the character setup. We will learn how to set up a weapon from scratch in the next section.

Last updated