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 MonoBehavior class, which acts as an interface between your controller and the rest of the system.
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.
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 protectedvoidInitAnimController()// Used to initialize the system and pending components// @cameraDelegate - your function for the camera updateprotected 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 Layerprotected 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 firingprotected void PlayCameraShake(FPSCameraShake shake)// Used to play a static poseprotected void PlayPose(AnimSequence motion)// Used to play dynamic animation from codeprotected void PlayAnimation(AnimSequence motion,float startTime =0f)// Used to stop currently playing animationprotected void StopAnimation(float blendTime =0f)
FPSAnimController.cs
// Procedural recoil componentprotectedRecoilAnimation recoilComponent;// Contains runtime player input data (e.g. mouse input)protectedCharAnimData charAnimData;// Used primarily for function calls from Animation Events// Runs once at the beginning of the next updateprotectedCoreToolkitLib.PostUpdateDelegate queuedAnimEvents;
Use examples
Let's see how these methods and properties should be implemented and used in your controller class:
Tip:UpdateCameraRotation is used to stabilize the camera, so it's not affected by the animations.
InitWeapon(FPSAnimWeapon weapon)
FPSController.cs
publicvoidEquipWeapon(){ //... your EquipWeapon() implementationInitWeapon(weapon); //weapon is a reference to the active weapon}
InitAimPoint(FPSAnimWeapon weapon)
FPSController.cs
publicvoidChangeScope() // Called when changing scopes{InitAimPoint(weapon); //weapon is a reference to the active weapon}
UpdateAnimController()
FPSController.cs
privatevoidUpdate(){ //... Your Update() implementationUpdateAnimController();}
PlayCameraShake(FPSCameraShake shake)
FPSController.cs
[SerializeField] privateFPSCameraShake shake;privatevoidFire() // Called when a shot is fired{ //... Your Fire() implementationPlayCameraShake(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)
[SerializeField] privateAnimSequence reloadClip;privatevoidReload(){ //... Your Reload() implementationPlayAnimation(reloadClip);}
StopAnimation(float blendTime = 0f)
privatevoidOnSprintPressed(){ //... Your OnSprintPressed() implementationStopAnimation(0.1f);}
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: