Character Controller Pro (1.4.x)
  • Introduction
  • The package
    • Content
    • Versioning scheme
    • Importing the package
    • Using the package
    • Known issues
  • Fundamentals
    • Core
      • Character
      • Character body
      • Character actor
        • States
        • Stable movement features
        • Velocity
    • Implementation
      • Character state controller
      • Character state
      • Character brain
  • How to...
    • Core
      • Create a basic character
      • Add behavior logic to your character
      • Move the character
      • Rotate the character
      • Leave grounded state (e.g. jump)
      • Change the size of the character
      • Disable collisions (ghost)
      • Use the character information (with examples)
      • Use root motion
      • Detect a character using a "detector"
      • Add a static one way platform
      • Add a dynamic one way platform
    • Implementation
      • Organize the character hierarchy
      • States
        • Add and configure the state machine
        • Create a state
        • Transition from one state to another
        • Handle animation
        • Modify an IK (inverse kinematics) element
      • Actions
        • Define your own actions
        • Use the character actions
        • Use a custom Input Handler
        • Use the new input system
        • Create your own AI movement logic
Powered by GitBook
On this page
  • Creating the Animator controller
  • Assigning a runtime controller
  • Using the Animator component
  1. How to...
  2. Implementation
  3. States

Handle animation

PreviousTransition from one state to anotherNextModify an IK (inverse kinematics) element

Last updated 2 years ago

Creating the Animator controller

To add a custom animator controller first create one.

Next, design the animation node based graph as you want.

Assigning a runtime controller

There are three possible approaches:

  1. You can assign one big runtime controller to the Animator component directly and ignore individual controllers (states).

  2. You can use a mix between 1 and 2.

Using the Animator component

Any state can access the Animator component by using the "Animator" public property from CharacterActor.

Animator animator = CharacterActor.Animator;

Once you got this reference you can do whatever you want. Here is a code snippet taken from the NormalMovement state (Demo):

public override void PostUpdateBehaviour(float dt)
{       
    if (!CharacterActor.IsAnimatorValid())
        return;
    
    CharacterActor.Animator.SetBool(groundedParameter , CharacterActor.IsGrounded);
    CharacterActor.Animator.SetBool(stableParameter , CharacterActor.IsStable);
    CharacterActor.Animator.SetFloat(verticalSpeedParameter , CharacterActor.LocalVelocity.y);
    CharacterActor.Animator.SetFloat(planarSpeedParameter , CharacterActor.PlanarVelocity.magnitude);
    CharacterActor.Animator.SetFloat(horizontalAxisParameter , CharacterActions.movement.value.x);
    CharacterActor.Animator.SetFloat(verticalAxisParameter , CharacterActions.movement.value.y);	
    CharacterActor.Animator.SetBool(isCrouchedParameter , isCrouched);        
    
}

It is recommended to set certain parameters during the PreCharacterSimulation and/or PostCharacterSimulation methods.

The reason for this is because the actor might modify the body velocity along the way, so the values won't be updated by the time the frame is rendered.

You can use individual runtime controllers from each state. For more information please read .

this