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
  • Getting the action struct
  • Reading the actions
  • Bool actions
  • Vector2 actions
  1. How to...
  2. Implementation
  3. Actions

Use the character actions

Getting the action struct

The CharacterActions struct can be obtained from the CharacterBrain component.

CharacterActions actions = characterBrain.CharacterActions;

If you are working from inside a state you can call the CharacterActions property (not the class):

CharacterActions actions = CharacterActions;

Reading the actions

Just access the public member you want from the CharacterAction struct.

// Bool action ---> E.g. Jump (button)
bool jumpValue = CharacterActions.jump.value;

// Float action ---> E.g. Horizontal (AD keys)
float horizontalValue = CharacterActions.horizontal.value;

// Vector2 action ---> E.g. Movement (WASD keys)
Vector2 movementValue = CharacterActions.movement.value;

Bool actions

Float and Vector2 actions are most of the time related to analog values. Their value is what's important. On the other hand, with bool actions it is often more important the "phase" of the action.

For a button, the phases are started (similar to the classic "GetButtonDown") and canceled ("GetButtonUp").

// Bool action ---> E.g. a jump button 
bool wasJumpPressed = CharacterActions.jump.Started;
bool wasJumpReleased = CharacterActions.jump.Canceled;

Vector2 actions

If you are using the old InputManager (the default input system used by the demo scenes) you can create a Vector2 action from the project settings, even though these type of actions are not supported.

The Vector2 action is just a mix between two float actions.

To define a Vector2 action you need to create two input axis:

  1. The Name of the action + space + "X"

  2. The Name of the action + space + "Y"

For instance, the "movement" action is defined like this:

PreviousDefine your own actionsNextUse a custom Input Handler

Last updated 4 years ago