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
  • What's this?
  • Why use this?
  • Custom behaviour
  • Example: Jump pad
  1. How to...
  2. Core

Detect a character using a "detector"

What's this?

A CharacterDetector is a component that's responsible for detecting characters (CharacterActor components). This component uses the OnTriggerXXX callbacks, meaning that any character can be detected in either two ways:

  1. Trigger vs Character's capsule collider

  2. Non-Trigger vs Character's ground trigger (you'll need to enable it in the inspector)

Why use this?

A CharacterDetector object:

  • Registers all the current characters inside a dictionary, avoiding multiple GetComponent calls.

  • Does its job only once, so you don't need to keep track of each individual colliders involved.

  • Works automatically with 2D and 3D physics.

Custom behaviour

It is possible to implement your own behaviour by implementing the CharacterDetector class. For example, the JumpPad and PositionAndRotationModifier components are essentially detectors.

There are three important methods that you can override in order to define the behaviour you want:

protected virtual void ProcessEnterAction( CharacterActor characterActor ){}
protected virtual void ProcessStayAction( CharacterActor characterActor ){}
protected virtual void ProcessExitAction( CharacterActor characterActor ){}

Example: Jump pad

public class JumpPad : CharacterDetector
{
    public float jumpPadVelocity = 10f;

    protected override void ProcessEnterAction( CharacterActor characterActor )
    {
        if( characterActor.GroundObject != gameObject )
            return;
        
        characterActor.ForceNotGrounded();
        characterActor.Velocity += transform.up * jumpPadVelocity;
    }

    protected override void ProcessStayAction( CharacterActor characterActor )
    {
        ProcessEnterAction( characterActor );
    }
    
}
PreviousUse root motionNextAdd a static one way platform

Last updated 3 years ago