πŸƒβ€β™‚οΈCharacter

In this section you will learn how to implement FPSAnimController

Step 1 - Implement FPSAnimController

Inherit your controller from FPSAnimController

Locate your character controller class and derive it from the FPSAnimController - an abstract MonoBehaviorarrow-up-right class, which acts as an interface between your controller and the rest of the system.

FPSController.cs
public class FPSController : FPSAnimController // <- 
{
    ...
}

If direct inheritance is not possible (e.g. when your controller is already derived from another class), you can try deriving your parent class or creating a standalone controller for the animation part only.

chevron-rightExamplehashtag

Let's create a standalone animation controller:

YourAnimController.cs
public class YourAnimController : FPSAnimController // <- 
{
    ...
}

After that, attach YourAnimController component to your character. You will need to update YourAnimController with player actions, such as move or look input, etc.

Methods and properties

Once you've derived your controller class from FPSAnimController, let's see what methods and properties this class brings:

FPSAnimController.cs
// Mostly used internally 
protected void InitAnimController()

// Used to initialize the system and pending components
// @cameraDelegate - your function for the camera update
protected void InitAnimController(CoreToolkitLib.PostUpdateDelegate cameraDelegate)

// Used to initialize weapon-related data, such as sway, viewmodel, etc.
protected void InitWeapon(FPSAnimWeapon weapon)

// Used to initialize active aim transform
// Used by the Ads Layer
protected void InitAimPoint(FPSAnimWeapon weapon)

// Should be called every frame in the end of the player update loop 
protected void UpdateAnimController()

// Used to play a recoil shake when firing
protected void PlayCameraShake(FPSCameraShake shake)

// Used to play a static pose
protected void PlayPose(AnimSequence motion)

// Used to play dynamic animation from code
protected void PlayAnimation(AnimSequence motion, float startTime = 0f)

// Used to stop currently playing animation
protected void StopAnimation(float blendTime = 0f)

Use examples

Let's see how these methods and properties should be implemented and used in your controller class:

InitAnimController(PostUpdateDelegate cameraDelegate)

circle-info

Tip: UpdateCameraRotation is used to stabilize the camera, so it's not affected by the animations.

InitWeapon(FPSAnimWeapon weapon)

InitAimPoint(FPSAnimWeapon weapon)

UpdateAnimController()

PlayCameraShake(FPSCameraShake shake)

FPSCameraShake is a scriptable object, used to play camera shakes when firing. You can create a new camera shake by right-clicking in any folder Create->FPS Animator->FPSCameraShake

PlayAnimation(AnimSequence motion)

StopAnimation(float blendTime = 0f)

Step 2 - Refresh input

Once all methods are implemented, it's time to properly update the input in runtime.

charAnimData property is responsible for all player-related input, such as leaning, movement, mouse delta, etc.

It won't be updated automatically, you need to insert the input-related logic into your code when a specific key or event is triggered. Here's the examples from the demo:

Leaning

circle-info

Tip: 1 defines right, and -1 defines left leaning direction.

Movement

Look

Step 3 - Refresh RecoilAnimation

The last step of the character integration is RecoilAnimation component. Here's what methods and properties you need to use in your controller class:

Update isAiming

Call Play and Stop

At this point character integration is fully complete. In the next section, you will learn how implement animation interface for your weapon class.

Last updated