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
  • Grounded state
  • Wall collision example
  • Wall running behavior
  • Slide movement
  1. How to...
  2. Core

Use the character information (with examples)

The term information here covers everything related to public getters and flags such as collision flags, physics contacts, triggers, grounding status, and so on. These values can be very useful when creating new gameplay mechanics.

Grounded state

if (CharacterActor.IsGrounded)
{
    DoGroundLogic();
}

Wall collision example

The same can be applied to some other property, for example, if we need to trigger some animation parameter only when the character is touching a wall:

if (CharacterActor.WallCollision)
{
    // Do wall collision logic.
}

Wall running behavior

if (!CharacterActor.IsGrounded && CharacterActor.WallCollision)
{
    // Do grounded logic.
}

Slide movement

Let's say our character is standing on a steep slope (unstable state) and we want to make it slide down. What we can do is getting the unstable state first and then applying the movement.

if (!CharacterActor.IsStable)
{
    // Do Slide
}

However, the character can be unstable while it's in the air, so we need to be sure the character is grounded as well:

if (!CharacterActor.IsStable && CharacterActor.IsGrounded)
{
    // Do Slide
}
if (CharacterActor.CurrentState == CharacterActorState.UnstableGrounded)
{
    // Do Slide
}

Now, lets add one more condition. We want to execute the slide movement 1 second after making contact with this unstable surface. One way to do this is by using a property called GroundedTime (you have also NotGroundedTime, StableGroundedTime and UnstableGroundedTime).

if (CharacterActor.CurrentState == CharacterActorState.UnstableGrounded)
{
    if (CharacterActor.GroundedTime >= 1f)
    {
        // Do Slide
    }    
}

So, this is the final code:

if( CharacterActor.CurrentState == CharacterActorState.UnstableGrounded )
{
    if( CharacterActor.GroundedTime >= 1f )
    {
        CharacterActor.Velocity += - CharacterActor.Up * slideAcceleration * Time.deltaTime;
    }    
}

PreviousDisable collisions (ghost)NextUse root motion

Last updated 6 months ago

We can simplify this condition by using the CurrentState property from the actor (for more information please read the section).

Making the character slide is very simple. Based on section, we know that only collide and slide is applied to the character. So, we need to move the character downwards, the collide and slide algorithm will handle that for us (also, the physics simulation does the same thing).

States
this