# Table of Contents - [Introduction | Character Controller Pro (1.4.x)](#introduction-character-controller-pro-1-4-x-) - [Content | Character Controller Pro (1.4.x)](#content-character-controller-pro-1-4-x-) - [Core | Character Controller Pro (1.4.x)](#core-character-controller-pro-1-4-x-) - [Character actor | Character Controller Pro (1.4.x)](#character-actor-character-controller-pro-1-4-x-) - [Core | Character Controller Pro (1.4.x)](#core-character-controller-pro-1-4-x-) - [Velocity | Character Controller Pro (1.4.x)](#velocity-character-controller-pro-1-4-x-) - [Known issues | Character Controller Pro (1.4.x)](#known-issues-character-controller-pro-1-4-x-) - [Implementation | Character Controller Pro (1.4.x)](#implementation-character-controller-pro-1-4-x-) - [Character | Character Controller Pro (1.4.x)](#character-character-controller-pro-1-4-x-) - [Versioning scheme | Character Controller Pro (1.4.x)](#versioning-scheme-character-controller-pro-1-4-x-) - [Importing the package | Character Controller Pro (1.4.x)](#importing-the-package-character-controller-pro-1-4-x-) - [States | Character Controller Pro (1.4.x)](#states-character-controller-pro-1-4-x-) - [Character body | Character Controller Pro (1.4.x)](#character-body-character-controller-pro-1-4-x-) - [Disable collisions (ghost) | Character Controller Pro (1.4.x)](#disable-collisions-ghost-character-controller-pro-1-4-x-) - [Character state | Character Controller Pro (1.4.x)](#character-state-character-controller-pro-1-4-x-) - [Using the package | Character Controller Pro (1.4.x)](#using-the-package-character-controller-pro-1-4-x-) - [Detect a character using a "detector" | Character Controller Pro (1.4.x)](#detect-a-character-using-a-detector-character-controller-pro-1-4-x-) - [Move the character | Character Controller Pro (1.4.x)](#move-the-character-character-controller-pro-1-4-x-) - [Stable movement features | Character Controller Pro (1.4.x)](#stable-movement-features-character-controller-pro-1-4-x-) - [Leave grounded state (e.g. jump) | Character Controller Pro (1.4.x)](#leave-grounded-state-e-g-jump-character-controller-pro-1-4-x-) - [Change the size of the character | Character Controller Pro (1.4.x)](#change-the-size-of-the-character-character-controller-pro-1-4-x-) - [Create a basic character | Character Controller Pro (1.4.x)](#create-a-basic-character-character-controller-pro-1-4-x-) - [Add behavior logic to your character | Character Controller Pro (1.4.x)](#add-behavior-logic-to-your-character-character-controller-pro-1-4-x-) - [Character state controller | Character Controller Pro (1.4.x)](#character-state-controller-character-controller-pro-1-4-x-) - [Rotate the character | Character Controller Pro (1.4.x)](#rotate-the-character-character-controller-pro-1-4-x-) - [Use the character information (with examples) | Character Controller Pro (1.4.x)](#use-the-character-information-with-examples-character-controller-pro-1-4-x-) - [Use root motion | Character Controller Pro (1.4.x)](#use-root-motion-character-controller-pro-1-4-x-) - [Character brain | Character Controller Pro (1.4.x)](#character-brain-character-controller-pro-1-4-x-) - [Implementation | Character Controller Pro (1.4.x)](#implementation-character-controller-pro-1-4-x-) - [States | Character Controller Pro (1.4.x)](#states-character-controller-pro-1-4-x-) - [Actions | Character Controller Pro (1.4.x)](#actions-character-controller-pro-1-4-x-) - [Add a static one way platform | Character Controller Pro (1.4.x)](#add-a-static-one-way-platform-character-controller-pro-1-4-x-) - [Organize the character hierarchy | Character Controller Pro (1.4.x)](#organize-the-character-hierarchy-character-controller-pro-1-4-x-) - [Use a custom Input Handler | Character Controller Pro (1.4.x)](#use-a-custom-input-handler-character-controller-pro-1-4-x-) - [Add a dynamic one way platform | Character Controller Pro (1.4.x)](#add-a-dynamic-one-way-platform-character-controller-pro-1-4-x-) - [Transition from one state to another | Character Controller Pro (1.4.x)](#transition-from-one-state-to-another-character-controller-pro-1-4-x-) --- # Introduction | Character Controller Pro (1.4.x) [NextContent](/ccp/package/content) Last updated 4 months ago Welcome to the online documentation for _Character Controller Pro_. [](#how-to-read-this) How to read this? -------------------------------------------- This documentation is separated into three parts: * The _**The package**_ section describes how the asset package should be downloaded, imported and updated. * The _**Fundamentals**_ section explains how the all the features work from a theoretical point of view. * The _**How to...**_ section is meant to be a very modular tutorial guide. [](#does-this-documentation-describe-classes-methods-and-fields) Does this documentation describe classes, methods and fields? ----------------------------------------------------------------------------------------------------------------------------------- It doesn't. For that, there is a [API reference](https://lightbug14.github.io/lightbug-web/character-controller-pro/Documentation/html/index.html) online. [](#how-can-i-know-what-a-particular-field-does-or-what-it-means) How can I know what a particular field does, or what it means? ------------------------------------------------------------------------------------------------------------------------------------- Take a look at the [tooltip](https://docs.unity3d.com/ScriptReference/TooltipAttribute.html) associated with a particular field. [](#is-this-documentation-old) Is this documentation old? -------------------------------------------------------------- The package version is indicated next to the title at the top left. Normally, the documentation is in sync with the latest version available. [](#i-have-an-older-version-of-ccp-what-should-i-do) I have an older version of CCP, What should I do? ----------------------------------------------------------------------------------------------------------- I always recommend to **get the latest version of the asset if possible.** That being said, most of the core concepts and features remain the same, so you should be able to use this documentation without any problem. [](#is-there-an-easy-way-to-get-started) Is there an easy way to get started? ---------------------------------------------------------------------------------- Go to the "_How to..."_ section. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LwaTyIdTGpIBaBxUC5y%252F-LwaUId5hrTgZ76GpqSd%252FKeyImage_Cover.png%3Falt%3Dmedia%26token%3D7069bb80-8c9f-4937-af71-227de7229cb9&width=768&dpr=4&quality=100&sign=c62221dc&sv=2) --- # Content | Character Controller Pro (1.4.x) The asset is divided into three main parts which are (from low-level to high-level): * Core * Implementation * Demo [](#core) Core ------------------- Consists of all the low-level components associated with the **character actor** itself. character actor ↔ character controller These components are responsible for allowing characters to detect obstacles, move, rotate, change size, react of physics, and much more. [](#implementation) Implementation --------------------------------------- This part consists mainly of two systems built around the character actor: 1. A finite state machine for managing different states. 2. An action system for handling input actions (player or AI) [](#demo) Demo ------------------- This part contains all the assets used for the demo. These assets go from character abilities/actions to UI components, meshes, sprites, and so on. All the demo content has been included for demo purposes only. [PreviousIntroduction](/ccp) [NextVersioning scheme](/ccp/package/versioning) Last updated 4 months ago --- # Core | Character Controller Pro (1.4.x) [Create a basic character](/ccp/how-to.../core/the-most-basic-character) [Add behavior logic to your character](/ccp/how-to.../core/add-logic-to-your-character) [Move the character](/ccp/how-to.../core/move-the-character) [Rotate the character](/ccp/how-to.../core/rotate-the-character) [Leave grounded state (e.g. jump)](/ccp/how-to.../core/leave-grounded-state-e.g.-jump) [Change the size of the character](/ccp/how-to.../core/scale-the-character) [Disable collisions (ghost)](/ccp/how-to.../core/disable-collisions-ghost-character) [Use the character information (with examples)](/ccp/how-to.../core/use-the-character-information) [Use root motion](/ccp/how-to.../core/use-root-motion) [Detect a character using a "detector"](/ccp/how-to.../core/detect-a-character-using-a-detector) [Add a static one way platform](/ccp/how-to.../core/add-a-static-one-way-platform) [Add a dynamic one way platform](/ccp/how-to.../core/add-a-dynamic-one-way-platform) [PreviousCharacter brain](/ccp/fundamentals/implementation/character-brain) [NextCreate a basic character](/ccp/how-to.../core/the-most-basic-character) --- # Character actor | Character Controller Pro (1.4.x) The _CharacterActor_ component can be also referred as a "character-oriented rigidbody". Most of the time you will be changing the position, rotation and/or the velocity of this component in order to create your own gameplay logic. The job of the CharacterActor is to **ensure that all the changes to the actor are being applied correctly based on a set of predefined "rules"**. The best way to explain this component is by exposing some of these rules and properties. [](#undefined) ------------------ [PreviousCharacter body](/ccp/fundamentals/untitled/characterbody) [NextStates](/ccp/fundamentals/untitled/character-actor/stability) Last updated 4 years ago --- # Core | Character Controller Pro (1.4.x) This section explains how the main parts of the **core** works. It's called the "core" because it contains all the low level components and functionalities used by the main elements of CCP. [PreviousKnown issues](/ccp/package/known-issues) [NextCharacter](/ccp/fundamentals/untitled/character-hierarchy) Last updated 4 years ago --- # Velocity | Character Controller Pro (1.4.x) [PreviousStable movement features](/ccp/fundamentals/untitled/character-actor/stable-movement-features) [NextImplementation](/ccp/fundamentals/implementation) Last updated 4 years ago This section explains how is the entire process behind the velocity calculation, from the beginning of the cycle until the end (after the simulation). The CharacterActor component handles three important velocity values during each cycle (FixedUpdate): Velocity Description Input velocity This vector is read by the CharacterActor component in order to move from point A to point B. Pre simulation velocity Determining the final position might require the input velocity to change. This value is feed to the physics simulation. Post simulation velocity After the simulation is done, the velocity might change once again. [](#input-velocity) Input velocity --------------------------------------- This vector is effectively the rigidbody velocity prior to the FixedUpdate call. It is called "Input" velocity since this is the value chosen by the user (gameplay logic). In order to set up this value you just need to modify the CharacterActor velocity: Copy CharacterActor.Velocity = someValue; [](#pre-simulation-velocity) Pre-simulation velocity --------------------------------------------------------- Technically speaking, this is the velocity created internally by the CharacterActor component, necessary to determinte the final destination of the character. This value is then fed to the physics simulation (hence the name). [](#post-simulation-velocity) Post-simulation velocity ----------------------------------------------------------- After the simulation is done, the post-simulation velocity is the resulting velocity of the rigidbody. Pre-simulation velocity and post-simulation velocity might be different, especially if the character collided with another rigidbody. The CharacterActor component allows you to choose which one of the three velocities mentioned before you want to re-assign as post-simulation velocity. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPSXh_Aby5j_kXrMTJi%252F-MPSYjX7-gJev5o2L1vn%252FVelocity.png%3Falt%3Dmedia%26token%3Dea1a30e7-0c6b-4f60-8f79-8ac0d470d273&width=768&dpr=4&quality=100&sign=c0357fff&sv=2) --- # Known issues | Character Controller Pro (1.4.x) [](#animation-is-ignored) Animation is ignored --------------------------------------------------- #### [](#description) Description The Animator does not recognize the _NormalMovement_ runtime animation controller (by default) even though it has been set up correctly. This may happen the **first time** the asset is imported. #### [](#unity-version) Unity version 2020.x.y #### [](#fix) Fix Restart the project. [PreviousUsing the package](/ccp/package/using-the-package) [NextCore](/ccp/fundamentals/untitled) Last updated 4 months ago --- # Implementation | Character Controller Pro (1.4.x) The _Implementation_ is a complete separate part of the asset that depends on the _Core_. Its main goal is to provide character-oriented systems that can be useful for the user. These are some of the terms the implementation uses a lot: StateController A finite state machine (FSM) used to handling each state. State Where the logic is stored. Brain This component handles everything related to actions Action An interface that represents a virtual input signal. [PreviousVelocity](/ccp/fundamentals/untitled/character-actor/velocity) [NextCharacter state controller](/ccp/fundamentals/implementation/character-state-controller) Last updated 4 years ago --- # Character | Character Controller Pro (1.4.x) [PreviousCore](/ccp/fundamentals/untitled) [NextCharacter body](/ccp/fundamentals/untitled/characterbody) Last updated 4 years ago [](#hierarchy) Hierarchy ----------------------------- The core components associated with the character controller do not require to be organized in a very specific way, although it is recommended to follow the following (very simple and functional) structure: Character This object represents the physics of the character (collider and rigidbody). This object will also have two very important components, the CharacterBody and the CharacterActor, **these components will provide a Rigidbody and Collider component for you**. Graphics This is an object in between the main physics object (Character) and the animated character (e.g. Animator). It becomes very useful when there is a need to modify the graphics (and model) without affecting the character (parent). Animated mesh/sprite Here, under "Graphics" is where you should put the character visual elements, such as 3D meshes, humanoids, sprites, etc. All the demo characters follow this hierarchy, there are even graphics-related component that were designed with this structure in mind (e.g. CharacterGraphicsRootController needs to be applied to "Graphics"). [](#components) Components ------------------------------- Based on the hierarchy from before, we can say the "Core" is divided into two parts: 1. Character components. 2. Graphics components. ### [](#character-components) Character components These components are **mandatory**! There are two main components: CharacterBody This component represents the body of the character. It takes care of the Collider and Rigidbody component. CharacterActor This components handles all the interactions of the character with the environment. This is considered as the "Character Controller". ### [](#graphics-components) Graphics components These components are much more focused towards an specific task (not as complex as the CharacterActor) and most of them are optional. The most important (and usually one component you'll always want to add to your character) is the **CharacterGraphicsRootController**. It is called "root" controller because it is supposed to be applied to the root of all graphic objects, in this case the "Graphics" object (see the hierarchy). ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPUyJHJx1pRTULHBIPU%252F-MPV9UDRgS7uQrNjSpNB%252Fimagen.png%3Falt%3Dmedia%26token%3D50797124-ff57-4374-909a-2100512607bc&width=768&dpr=4&quality=100&sign=37687c2f&sv=2) --- # Versioning scheme | Character Controller Pro (1.4.x) [PreviousContent](/ccp/package/content) [NextImporting the package](/ccp/package/setting-up-the-project) Last updated 4 months ago Type Description Patch It consists of fixes of all kind (bugs, comments, typos, descriptions, etc.). This update is **always recommended.** Minor It consists of new features and improvements. Unfortunately, such changes could introduce API incompatibilities, and because of that, it is always recommended to follow the corresponding upgrade guide. Major A re-design of the asset. Compatibility will be compromised for sure. Important: A major release will be introduced as a new (asset store) package. This means the new release doesn't replace the old one. [](#how-to-update) How to update ------------------------------------- Even though Unity is smart enough to replace all modified files, the recommended way to update the asset is by **deleting the** _**Character Controller Pro**_ **folder** and then import the new version. It is always recommended to update to a newer version of the package whenever possible, unless the **risk** of doing so is high enough for your particular project. The demo content included with the package does not follow any versioning scheme. Risk: **Zero** Risk: **Low to medium** Risk: **Maximum** ✅ ⚠️ ☢️ ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252F8IifQ2KxgZin0ppZf4ws%252Fimage.png%3Falt%3Dmedia%26token%3D102f9dd7-bf3b-4990-972a-c3cb04acb3c8&width=768&dpr=4&quality=100&sign=3b4de95&sv=2) --- # Importing the package | Character Controller Pro (1.4.x) [PreviousVersioning scheme](/ccp/package/versioning) [NextUsing the package](/ccp/package/using-the-package) Last updated 4 months ago [](#welcome-window) Welcome window --------------------------------------- Right after importing the package, **a big welcome screen should appear on screen**. This screen contains some useful information so please be sure to read it. You can access this screen at any time by going to "_Window/Character Controller Pro/Welcome_". [](#running-the-demo-content) Running the demo content ----------------------------------------------------------- Character Controller Pro as a tool does NOT require any specific project settings to be able to function properly. That being said, the Demo included with the package rely on some specific project settings (inputs, tags and layers). In order to play the demo scenes, the project settings has to be modified. In order to simply this tedious process, **presets have been** included as part of the package. For more information about presets please see [this](https://docs.unity3d.com/Manual/Presets.html) link. Example: Applying Input setting (Input preset) Go to the _InputManager_ and open the preset window (top right, see the image) Select the preset by double clicking it: ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LzEDZTxT5DzSyWg2RDZ%252F-LzETQ5g1OOg9TAVrTWP%252Fimagen.png%3Falt%3Dmedia%26token%3D5115f046-2169-407c-b701-69d54a8c6ec0&width=300&dpr=4&quality=100&sign=f15c18ab&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LzEDZTxT5DzSyWg2RDZ%252F-LzERx2bP40o0wzvGP2H%252Fimagen.png%3Falt%3Dmedia%26token%3D01021333-aede-41de-818b-5bb0899c25e8&width=300&dpr=4&quality=100&sign=5ead37b7&sv=2) --- # States | Character Controller Pro (1.4.x) [PreviousCharacter actor](/ccp/fundamentals/untitled/character-actor) [NextStable movement features](/ccp/fundamentals/untitled/character-actor/stable-movement-features) Last updated 3 years ago This character controller state can be defined at any time as a mix between two very important properties: * Ground state (grounded, not grounded). * Stability (stable, unstable). [](#grounded-state) Grounded state --------------------------------------- This property indicates if there is ground below the character, simple as that. This property alone does not influence the actor internal logic at all, that's something the stability does. The main property associated with the grounded state is the **IsGrounded** public property. There are much more properties associated with the current ground (see the API reference for more info). Due to how the character projects its own velocity, **it is not possible to leave the grounded state by applying a vertical velocity**. [](#stability) Stability ----------------------------- The internal logic of the character controller works differently depending on the current stability state. That is, if the character is stable then it uses most of the features from the controller (velocity projection, step up, step down, edge compensation, and so on). If it is not, then most of the features are disabled. A character is _**stable**_ when it is grounded and the _**stable slope angle**_ (see the API reference) is less than or equal to the _**slope limit**_ value. Copy IsStable = IsGrounded && ( stableSlopeAngle <= slopeLimit ); The stable slope angle is selected internally by the character actor based on a few conditions. For example, take a look at the following image: There are two surfaces in which one of them is unstable (red) and the other one is stable (green). The stable normal is chosen as the one coming from the stable surface. This normal determines the movement displacement direction. On the other hand, the contact normal corresponds to the normal obtained by the physics query (e.g. CapsuleCast). [](#states) States ----------------------- Based on what has been said before, the character actor can be: CharacterActorState IsStable IsGrounded Description StableGrounded true true There is ground below the character and it is a stable surface. Most of the features are processed. UnstableGrounded false true There is ground below the character, however, it is not a stable surface. Features are bypassed. NotGrounded false false Same as before, however there is no ground below. Getting a particular state is equivalent to get the two properties separately. For example: Copy //----------------------------------------------------------------------------- // Using properties if( CharacterActor.IsGrounded && !CharacterActor.IsStable) { ProcessUnstableGroundedLogic(); } // ---------------------------------------------------------------------------- // Using the CharacterActor state if( CharacterActor.CurrentState == CharacterActorState.UnstableGrounded ) { ProcessUnstableGroundedLogic(); } ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Lyt9souh6_VeUiYsTZu%252F-LytC_QvICuo4IDVIo-A%252FcontactVsStable.png%3Falt%3Dmedia%26token%3Db2917268-34cb-4ec3-ba30-f97d34c3ab3f&width=768&dpr=4&quality=100&sign=d76f2f5f&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPW4_EBkIIWVQ_HaVUG%252F-MPWDjoDKsQiE9qLruvC%252Fimagen.png%3Falt%3Dmedia%26token%3Dfe0a1b6a-2338-4308-8895-a13a05962b54&width=768&dpr=4&quality=100&sign=b8180037&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPVzh2X15N5lwTtNr29%252F-MPW1qgqijHc-rFFxS7N%252Fimagen.png%3Falt%3Dmedia%26token%3D74da19a7-01bd-4d97-bc82-85774aa089ec&width=768&dpr=4&quality=100&sign=7052e3fb&sv=2) --- # Character body | Character Controller Pro (1.4.x) [PreviousCharacter](/ccp/fundamentals/untitled/character-hierarchy) [NextCharacter actor](/ccp/fundamentals/untitled/character-actor) Last updated 4 years ago [](#properties) Properties ------------------------------- ### [](#foot-position-origin) Foot position (origin) The foot position is considered as the origin, a point of reference for everything. As is normally for character controllers, the origin is assumed to be the bottom most point of the character body. In this case is the bottom point of the capsule. ### [](#orientation) Orientation The character is modeled as an upright capsule. ### [](#size) Size Since this is a capsule-based character we need only to define the radius and the height to fully describe the size of the character. The _CharacterActor_ will consider the character dimensions as: The Width and Height values are represented with the _body size_ (a _Vector2_). In play mode the collider bottom offset will be automatically adjusted, depending on the current state (state vs unstable). ### [](#scale) Scale Even though the collider will be scaled just fine, the internal "physics size'' (responsible for physics queries) will not. So, **it is NOT recommend to scale the character using the** _**Transform**_ **component**. #### [](#what-if-i-want-to-scale-my-character) What if i want to scale my character? Well, in that case you should scale the graphics object, not the character itself (root object). After that, the body size should be modified to fit the graphics. Width\=2×Collider.RadiusWidth = 2 \\times Collider.RadiusWidth\=2×Collider.Radius Height\=Collider.HeightHeight = Collider.HeightHeight\=Collider.Height The character _localScale_ should always be <1,1,1\>< 1, 1 , 1 ><1,1,1\>. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyszPv43kuqJjRSm4ZW%252F-Lyt17HC8lzhorX1r-cU%252FcapsuleUpright.png%3Falt%3Dmedia%26token%3De5c4ee88-56c1-4227-85b6-9254ae6db180&width=768&dpr=4&quality=100&sign=eb4322d8&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyszPv43kuqJjRSm4ZW%252F-Lyt290Y6rJEUH8xB6hl%252FcapsuleBodyDimensions.png%3Falt%3Dmedia%26token%3Df3ed92b4-3181-4d1b-96e7-705685e494ad&width=768&dpr=4&quality=100&sign=1c297337&sv=2) --- # Disable collisions (ghost) | Character Controller Pro (1.4.x) There are currently two ways an actor (_Rigidbody_) can be able to properly ignore obstacles in the scene: [](#disabling-the-collider-component) Disabling the collider component --------------------------------------------------------------------------- The actor uses a _ColliderComponent_ component which is a wrapper around a 2D/3D collider. Enabling or disabling this component will automatically enable/disable the collider. Copy CharacterActor.ColliderComponent.enabled = enableCollider; [](#configuring-the-collision-matrix) Configuring the collision matrix --------------------------------------------------------------------------- Another way to make a ghost character is by changing the collision matrix from the Physics (Physics2D) settings. By default, the character actor uses the current collision matrix for all collision detection methods. [PreviousChange the size of the character](/ccp/how-to.../core/scale-the-character) [NextUse the character information (with examples)](/ccp/how-to.../core/use-the-character-information) Last updated 4 months ago --- # Character state | Character Controller Pro (1.4.x) A state is a component that defines the gameplay logic associated with the CharacterActor component. [](#state-vs-monobehaviour) State vs Monobehaviour ------------------------------------------------------- States work in the same way monobehaviours work: 1. They process some task over and over again in a frame by frame basis (the behaviour). 2. They are updated by a controller of some kind (the state controller). The big advantage of putting code inside a state, rather than using a monobehaviour, is: 1. The controller communicates better between other states, allowing you to create transitions between them. 2. Since they are part of a FSM, only one of them will be running at a time. 3. The controller is designed with a few components in mind (other states, animator, actions, character actor, etc.). [](#state-behaviour) State behaviour ----------------------------------------- Every state presents its own behaviour, and can be implemented through its abstracts and virtual methods. In order to define the state behaviour you'll need to override some specific methods from the _CharacterState_ component. For instance, if you want to create your own "exit behaviour" (executed when leaving a state) you can do something like this: Copy // YourCustomState.cs public override void ExitBehaviour(float dt) { // Your code ... } [](#transitions) Transitions --------------------------------- A transition, from a code point of view, consists of a set of conditions required by the state machine when switching from one state to another. This state machine in particular divides a transition into two parts, one for the current state ("from state") and one for the potential next state ("to state"). From state State where the transition originates. To state State where the transition ends. These transitions are called Exit transition and Enter transition. Exit transition This is the part of the transition that is evaluated first, when trying to exit the current state (hence its name). Enter transition This is the part of the transition that is evaluated secondly, when trying to enter the next state (hence its name). ### [](#exit-transition) Exit Transition Inside _CheckExitTransition,_ you would normally add potential target states to a queue. Note that there might be more than one potential state (candidate) at the same time. This is why there is a queue of states. #### [](#example) Example: Copy public override void CheckExitTransition() { if( conditionA ) { CharacterStateController.EnqueueTransition(); } else if( conditionB ) { CharacterStateController.EnqueueTransition(); CharacterStateController.EnqueueTransition(); } } ### [](#enter-transition) Enter transition _CheckEnterTransition_ will be called for all the states contained inside the queue. If this method returns true, that means the transition has been validated. #### [](#example-1) Example: The following transition should be validated only if the _fromState_ state is of type _ExampleState_: Copy public override bool CheckEnterTransition(CharacterState fromState) { if (fromState.GetType() != typeof(ExampleState)) return false; return true; } [PreviousCharacter state controller](/ccp/fundamentals/implementation/character-state-controller) [NextCharacter brain](/ccp/fundamentals/implementation/character-brain) Last updated 4 months ago --- # Using the package | Character Controller Pro (1.4.x) [PreviousImporting the package](/ccp/package/setting-up-the-project) [NextKnown issues](/ccp/package/known-issues) Last updated 4 months ago [](#namespaces) Namespaces ------------------------------- _Lightbug.CharacterControllerPro_ The main "root namespace" for this asset. _Lightbug.CharacterControllerPro.Core_ The _core_ code is hosted here (character actor, body, graphics, etc.). _Lightbug.CharacterControllerPro.Implementation_ The _implementation_ code is hosted here (state machine, state, actions, brain,platforms, etc.). _Lightbug.CharacterControllerPro.Demo_ The demo code is hosted here (specific character states, demo scenes, menus, fps counters, etc. ). _Lightbug.Utilities_ Here you will find all kind of useful static methods and extensions. [](#assembly) Assembly --------------------------- Assembly definitions are great when a tool/asset code needs to be isolated from game-related code. For more information about why custom assemblies can be useful, please read the [documentation](https://docs.unity3d.com/2019.1/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html) . _Character Controller Pro_ has includes its own assembly definition (_com.lightbug.character-controller-pro_). ### [](#modifying-scripts-from-the-demo) Modifying scripts from the demo **Before version 1.4.11**, all the scripts were included as part of the main assembly. As a result, **if a user wanted to modify demo components directly, he or she had to move the content they want outside the assembly** (e.g. _Assets/MyContent_). Otherwise, only scripts outside the assembly will be able to reference these demo scripts, but not the other way around. For example: From version 1.4.11 onwards, **all demo scripts have been moved outside the assembly**. This means that by default, **all these scripts live under the main C# assembly** (_Assembly-CSharp_). Because of this, the issue mentioned before is gone: ### [](#referencing-the-assembly) Referencing the assembly If you are using a custom assembly definition and you need to reference _Character Controller Pro_ from within your assembly, you just need to go to the assembly definition file and add this reference: [](#api-reference) API reference ------------------------------------- The API reference is [available online](https://lightbug14.github.io/lightbug-web/character-controller-pro/Documentation/html/index.html) . This documentation has been generated from the code itself using doxygen. There is no need to have this reference open, just type the method you want to use and the IDE/code editor should be able to show a description of it. [](#inspector-fields) Inspector fields ------------------------------------------- All relevant (serialized) fields have a [tooltip description](https://docs.unity3d.com/ScriptReference/TooltipAttribute.html) associated with them. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252FOb6fTYRFSyWB7yXn3ozz%252Fimage.png%3Falt%3Dmedia%26token%3D19962802-0eeb-48f8-a3ac-311cdc0a2577&width=768&dpr=4&quality=100&sign=a0281154&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252Fx3YvFZmCmebqopkwnECa%252Fimage.png%3Falt%3Dmedia%26token%3D62faadd1-d409-462a-97d9-f888ff61c95a&width=768&dpr=4&quality=100&sign=bf4ecd93&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252FnHkNGo8G92zXHtFjtUEF%252Fimage.png%3Falt%3Dmedia%26token%3Dc01eb930-7e91-4737-9616-c13085269e9b&width=768&dpr=4&quality=100&sign=474e2e09&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252FIUO8y4GBUMlWHGL36hVt%252Fimage.png%3Falt%3Dmedia%26token%3D9c2c9474-bead-4a8b-851f-6f6a5a99ba47&width=768&dpr=4&quality=100&sign=d0d97a14&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LzNmKd5iWzr4JkaMKjg%252F-LzO9xkbvPVt9u9nC0cY%252Fimagen.png%3Falt%3Dmedia%26token%3Daf9ce263-bf1c-45a9-82ae-898c7eb184f9&width=768&dpr=4&quality=100&sign=10d0bf29&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MUW4ie_B3HtkTxSu4Ju%252F-MUW7Sz6REUIrq8qlccZ%252Fimagen.png%3Falt%3Dmedia%26token%3D9e712e61-8e09-4067-8e4b-a641291b925d&width=768&dpr=4&quality=100&sign=921b173&sv=2) --- # Detect a character using a "detector" | Character Controller Pro (1.4.x) [](#whats-this) 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) 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) 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: Copy protected virtual void ProcessEnterAction( CharacterActor characterActor ){} protected virtual void ProcessStayAction( CharacterActor characterActor ){} protected virtual void ProcessExitAction( CharacterActor characterActor ){} ### [](#example-jump-pad) Example: Jump pad Copy 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 motion](/ccp/how-to.../core/use-root-motion) [NextAdd a static one way platform](/ccp/how-to.../core/add-a-static-one-way-platform) Last updated 3 years ago --- # Move the character | Character Controller Pro (1.4.x) The character can be moved in three different ways: [](#modifying-position) Modifying Position ----------------------------------------------- This property modifies the rigid body position, but **without breaking Interpolation**. Copy CharacterActor.Position = position; [](#using-the-teleport-method) Using the Teleport method ------------------------------------------------------------- Teleporting an actor means changing its position instantly and also **breaking interpolation**. Additionaly, a dedicated event (OnTeleport) will be called. Copy CharacterActor.Teleport(position); [](#modifying-velocity) Modifying Velocity ----------------------------------------------- This property modifies the rigid body velocity. Copy CharacterActor.Velocity = velocity; [PreviousAdd behavior logic to your character](/ccp/how-to.../core/add-logic-to-your-character) [NextRotate the character](/ccp/how-to.../core/rotate-the-character) Last updated 4 months ago --- # Stable movement features | Character Controller Pro (1.4.x) [PreviousStates](/ccp/fundamentals/untitled/character-actor/stability) [NextVelocity](/ccp/fundamentals/untitled/character-actor/velocity) Last updated 2 years ago These features from the CharacterActor component (as seen in the previous section) **will be applied only if the character is stable**. [](#movement) Movement --------------------------- ### [](#velocy-projection) Velocy projection Internally, when the character is stable, the CharacterActor component will project the input velocity (Linear Velocity) onto the current ground surface (Projected Velocity). This process will always maintain the initial velocity magnitude, regardless of the slope angle. ### [](#collide-and-slide) Collide and Slide This algorithm is responsible for determining obstacles along the way. If the encountered surface is allowed the character will walk onto it (maintaining always the displacement magnitude). if not, the slope will be considered as an invisible wall. [](#grounding) Grounding ----------------------------- ### [](#step-up-down) Step up/down This feature is responsible for putting the character on the ground (if there is one). There are two important values to consider: * **Step up distance:** Any stable surface below this height will be walkable by the character. * **Step down distance:** When losing contact with the ground, if the distance between the character and the ground is less or equal to this value, then the character will be automatically _grounded_ (sticking to the ground)_._ If there is no ground at all, then the character will be _not grounded_. ### [](#edge-compensation) Edge Compensation Normally, when a character is standing **on an edge** it collision shape will make contact with it. What edge compensation does is to lift up the capsule, simulating a cylinder shape. This feature only works on edges, for slopes you will get the same results as before (with edge compensation disabled). ### [](#dynamic-ground) Dynamic Ground If the current ground the character is standing on moves/rotates, then the character will move and/or rotate with it (only yaw rotation allowed). A valid dynamic ground **must be updated during the physics simulation**. Here are some valid examples: * **Kinematic rigidbody** that moves/rotates using **MovePosition**/**MoveRotation**. * **Kinematic/Dynamic rigidbody** that moves/rotates based on an **animation clip**. The update mode must be _AnimatePhysics_ (_Animator_ component)**.** * **Dynamic rigidbody** that moves/rotates using linear **velocity, angular velocity, forces, torque,** etc. [](#rigidbody-interactions) Rigidbody interactions ------------------------------------------------------- ### [](#weight) Weight If the character is standing on top of a dynamic rigidbody, it will automatically apply a force downwards at the contact point, proportional to the rigidbody mass. ### [](#push) Push The character can push other dynamic rigidbodies by colliding with them. It is also possible to ignore some rigidbodies by using a dedicated layermask: ​ ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fgitbook-28427.appspot.com%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Lyt9souh6_VeUiYsTZu%252F-LytFnIU3mJv2SpAT3_q%252FSlopes_3D.png%3Falt%3Dmedia%26token%3D4b2637cd-a160-4c7f-b9b0-f44c8c9d06fc&width=300&dpr=4&quality=100&sign=b725fd71&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fgitbook-28427.appspot.com%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Lyt9souh6_VeUiYsTZu%252F-LytFrrCQmHQOtJv-a52%252FSlopes_3D_allowed.png%3Falt%3Dmedia%26token%3D5102a348-1c78-47a4-9ded-db24192f7dad&width=300&dpr=4&quality=100&sign=5d7bd66&sv=2) Step up. Step down. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252Fzm8G9ox2GMgjCHsJo5Pg%252Fimage.png%3Falt%3Dmedia%26token%3Da5cdb3d1-169c-4a5c-9a66-2755dcd1f0d0&width=768&dpr=4&quality=100&sign=6ea587e9&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Lyt9souh6_VeUiYsTZu%252F-LytE27B2MuyQdEi8JA_%252FVelocityProj.png%3Falt%3Dmedia%26token%3Db9353706-03db-4923-a0ed-5aae19eceb04&width=768&dpr=4&quality=100&sign=ee3ee879&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPWlePedHommhx0J4xj%252F-MPWmundmmJnLvzFx7ao%252Fimagen.png%3Falt%3Dmedia%26token%3D58950cae-703e-4991-abad-3d06ce272ac3&width=768&dpr=4&quality=100&sign=8b7da39b&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MHr2xkNqmsMIFkN2PxE%252F-MHrAsfWP9DcxjQYJNaP%252Fbitmap2.png%3Falt%3Dmedia%26token%3D6c4c75fc-4740-4fba-813e-d39b610d8b78&width=768&dpr=4&quality=100&sign=2437c69a&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LytPeyy69sz0pbYQBSR%252F-LytPhwfi7DKWBBB9ceD%252Fdynamic.png%3Falt%3Dmedia%26token%3Dfc07002a-cad4-42de-87e6-9aed3f9bbea4&width=768&dpr=4&quality=100&sign=2028790d&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LytOGHUUUb7hwiIBiVn%252F-LytOSQrFpnp3IgRxMpM%252FledgeNormal.png%3Falt%3Dmedia%26token%3Dd1971e15-fb76-4822-b919-4abd0b74c9b2&width=300&dpr=4&quality=100&sign=21914d62&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LytOGHUUUb7hwiIBiVn%252F-LytOtCAOJgou3OH9UtC%252FledgeOn.png%3Falt%3Dmedia%26token%3Dc9f97845-2ec6-4394-aa82-9bb8e06186a5&width=300&dpr=4&quality=100&sign=486734df&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MHr2xkNqmsMIFkN2PxE%252F-MHrAsfVhyWTYDeF0Izt%252Fbitmap.png%3Falt%3Dmedia%26token%3D78c3da17-d8ab-4dda-9706-62943c592311&width=768&dpr=4&quality=100&sign=dcabf799&sv=2) --- # Leave grounded state (e.g. jump) | Character Controller Pro (1.4.x) If the character is stable, any vertical velocity applied to it will be eventually ignored by the _CharacterActor_ component. **The only way to leave grounded state is by forcing this state via the** _**CharacterActor**_ **API**, this can be done thanks to the _**ForceNotGrounded**_ method. You can do the opposite, that is, go from "not grounded" to "grounded" by calling **ForceGrounded**. [](#jump-example) Jump example ----------------------------------- If you want your character to jump, first force the "not grounded" state, and then apply the vertical velocity required for the jump: Copy CharacterActor.ForceNotGrounded(); CharacterActor.VerticalVelocity = CharacterActor.Up * JumpSpeed; [PreviousRotate the character](/ccp/how-to.../core/rotate-the-character) [NextChange the size of the character](/ccp/how-to.../core/scale-the-character) Last updated 4 months ago --- # Change the size of the character | Character Controller Pro (1.4.x) As mentioned in the [Character body](/ccp/fundamentals/untitled/characterbody#scale) section, **the local scale of the character should be <1,1,1> always**. In order to modify the size of the character, you can use the following _CharacterActor_ methods: [](#setsize) SetSize ------------------------- Changes the size of the actor without checking for obstacles. Copy CharacterActor.SetSize(size, sizeReferenceType); [](#checksize) CheckSize ----------------------------- It performs an overlap test using the target size. Copy CharacterActor.CheckSize(position, size, in filter); [](#checkandsetsize) CheckAndSetSize ----------------------------------------- It performs an overlap test using the target size. If the test is valid (a.k.a no obstacles detected), it changes the size. Copy CharacterActor.CheckAndSetSize(position, size, in filter, sizeReferenceType); [](#checkandinterpolate) CheckAndInterpolate ------------------------------------------------- It performs an overlap test using the target size. If the test is valid (a.k.a no obstacles detected), it begins to lerp the size from current to target size. Copy CharacterActor.CheckAndInterpolateSize(size, lerpFactor, in filter, sizeReferenceType); [PreviousLeave grounded state (e.g. jump)](/ccp/how-to.../core/leave-grounded-state-e.g.-jump) [NextDisable collisions (ghost)](/ccp/how-to.../core/disable-collisions-ghost-character) Last updated 4 months ago --- # Create a basic character | Character Controller Pro (1.4.x) [PreviousCore](/ccp/how-to.../core) [NextAdd behavior logic to your character](/ccp/how-to.../core/add-logic-to-your-character) Last updated 4 months ago Here is how the most simple character can be created: 1. Create an empty GameObject 2. Add a _CharacterBody._ 3. _Add a CharacterActor_ Adding a _CharacterActor_ first will automatically add a _CharacterBody_ Local scale should be <1,1,1> always. As you can see, there is no need to manually add a _**Collider**_ and a _**Rigidbody**_ to the object. The _CharacterBody_ component will handle this for you. This character **does absolutely nothing**. In order to give it some life you need to implement movement logic on top. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252FR6HRaefTwzza0h7JTUyE%252Fimage.png%3Falt%3Dmedia%26token%3D42a905f2-7962-47ea-88f1-03f77304a4f7&width=768&dpr=4&quality=100&sign=aa5d0678&sv=2) --- # Add behavior logic to your character | Character Controller Pro (1.4.x) [](#getting-a-reference-to-the-actor) Getting a reference to the actor --------------------------------------------------------------------------- Copy using UnityEngine; using Lightbug.CharacterControllerPro.Core; //<-- Required public class CharacterLogic: Monobehaviour { [SerializeField] CharacterActor characterActor = null; } [](#update-message) Update message --------------------------------------- Because the actor is a rigid body that's going to be affected by the physics simulation, all the logic must be located on _FixedUpdate_. Copy using UnityEngine; using Lightbug.CharacterControllerPro.Core; //<-- Required public class CharacterLogic: Monobehaviour { [SerializeField] CharacterActor characterActor = null; void FixedUpdate() { // Put the logic here ... } } [](#execution-order) Execution order ----------------------------------------- Because the actor runs its own update, it is important for the behavior logic (user-defined) to run before it. In Unity the execution order of scripts can be specified either in the project settings, or as a c# attribute called [_DefaultExecutionOrder_](https://docs.unity3d.com/ScriptReference/DefaultExecutionOrder.html) . By default, the _CharacterActor_ class uses an execution order of 10. This means all scripts without the attribute (execution order = 0) will run before _CharacterActor_, which is what we want. Copy //CharacterActorOrder = 10 [DefaultExecutionOrder(ExecutionOrder.CharacterActorOrder)] public class CharacterActor : MonoBehaviour { ... } [PreviousCreate a basic character](/ccp/how-to.../core/the-most-basic-character) [NextMove the character](/ccp/how-to.../core/move-the-character) Last updated 4 months ago --- # Character state controller | Character Controller Pro (1.4.x) [PreviousImplementation](/ccp/fundamentals/implementation) [NextCharacter state](/ccp/fundamentals/implementation/character-state) Last updated 2 years ago This component is essentially a "character-oriented" finite state machine (FSM) that also includes some other useful functionalities that will help you handle animation, actions and movement. This component can be considered as a "high level character controller". [](#finite-state-machine) Finite State Machine --------------------------------------------------- This component implements a "Finite State Machine" (FSM). This machine is responsible for managing and executing all the valid states of the character and computing the transitions between them. A simple and crude representation of the structure of a state machine is shown in the next image: The main loop cycle of the _CharacterStateController_ component (simplified version) is shown in the next figure: [](#movement-direction) Movement direction ----------------------------------------------- Input signals by their own do not translate into gameplay, often they need to be converted into 3D world space (a vector) in order to be processed or sent to another component. For instance, if we want to move out character using the WASD keys, we want to convert that input action (Vector2 in this case) into a velocity value (Vector3). This is what the input movement reference does. This vector is just the result of super basic algebra between input data and a transform component. All the information needed to create it can be obtained from inside the state. So, **it's ok if you don't want to use it for your own state logic**, just know that it is there. The input movement reference is just the combination of two concepts, **input reference** and **movement reference**. ### [](#input-reference) Input reference The input reference is a vector created exclusively by input actions (AI or Human), in this case by the _input axes_ information. By default the _input axes_ are defined as a _Vector2_ that contains the _Horizontal_ and _Vertical_ axes values. Basically what this does is **mapping the input data into 3D space**. ### [](#movement-reference) Movement reference A _movement reference_ is defined as a set of orthonormal vectors (think of the typical _right, up and forward_ vectors set) that are built based on a given reference. There are three types of references available: Reference Type Description World The reference uses the world coordinates, this means that the _right_, _up_ and _forward_ directions are equals to `Vector3.right`, `Vector3.up` and `Vector3.forward` respectively. Character The reference uses the own character transform (`transform.right`, `transform.up` and `transform.forward`) to update its components. External The reference uses an external transform to update its components. ### [](#input-movement-reference) Input movement reference By multiplying the **input reference** with the **movement reference** it is possible to create sort of a mix between inputs and movement, hence the name. To better clarify this concept see the figure. There are three cases: World, Character and external, in which **the same input axes vector (in this case the "right" action) is applied to each one of them**. The figure shows three very different results, depending on the movement reference used: [](#animation) Animation ----------------------------- ### [](#runtime-animator-controller) Runtime animator controller By default the runtime animator controller used will be the one from the Animator component itself. This means that one big controller will need to contain all the animation state machine for all your states. if this doesn't sound too good for you, there is one alternative that might help. If you don't like this approach you can totally ignore it. This approach is 100% optional. inputReference\= inputReference = < inputAxes.x , 0 , inputAxes.y > inputReference\= Mecanim (the system behind the Animator controller logic) can be really good and intuitive for some tasks, especially if you are not a coder, but sometimes can be a living nightmare . CCP implements a **multi-controller** approach, this means that each state component is capable of overriding the Animator runtime controller. 🤬 A representation of the state machine. Main loop of the state controller (simplified). Input movement reference calculation. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvejMlRrkGozNq4v6D%252F-LyvjxLTmBMusZ9f2WVM%252FmovementRef.png%3Falt%3Dmedia%26token%3D3c90fb0f-29a3-4b4b-bb97-9ecb3f848e63&width=768&dpr=4&quality=100&sign=53722f78&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvejMlRrkGozNq4v6D%252F-Lyvk9pcIlEzBGgkySSq%252FMovementRefDiagram.png%3Falt%3Dmedia%26token%3Db376f5af-5d93-40b9-a76f-e7d2ccb8a9cf&width=768&dpr=4&quality=100&sign=48c1f6af&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvejMlRrkGozNq4v6D%252F-Lyvgoace4iHZQzhydBq%252FFSM.png%3Falt%3Dmedia%26token%3D1e04656a-77c9-4d95-8c92-dca6c9cc4a39&width=768&dpr=4&quality=100&sign=1162b42b&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvejMlRrkGozNq4v6D%252F-LyvjKC8SnTkjNzpVMHs%252FFSM_Loop.png%3Falt%3Dmedia%26token%3Dac0391dc-a9c7-4c41-811f-164c7683b0ad&width=768&dpr=4&quality=100&sign=15d46f33&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPXOcmNCpuIqJ33VU30%252F-MPXPEc5_L0GcJe9j_1u%252Fimagen.png%3Falt%3Dmedia%26token%3D213db908-c7ec-4473-8cd3-0ba8e8a27949&width=768&dpr=4&quality=100&sign=ebc0b653&sv=2) --- # Rotate the character | Character Controller Pro (1.4.x) [](#id-3d-characters) 3D Characters ---------------------------------------- ### [](#assigning-a-rotation) Assigning a Rotation Same as transform.rotation, you can set the _**Rotation**_ property directly using any Quaternion value you want. Copy CharacterActor.Rotation = SomeQuaternion; ### [](#setting-a-direction-property) Setting a direction property Sometimes it is preferred to make a particular direction to point towards another one. In that case, you could modify any of the actor directions (properties): Copy CharacterActor.Forward = LookingDirection; By setting any of the direction properties there is no guarantee that the rotation applied will be the one you want. For instance, multiplying Forward by -1 does not mean a 180° Yaw rotation will be applied. For more precise control over the rotation process, please use `RotateYaw`, `RotatePitch` and/or `RotateRoll`. ### [](#using-the-actor-public-methods) Using the actor public methods If you want get a more precise result, you can use `RotateYaw`, `RotatePitch` and/or `RotateRoll`. These are all simple implementations based on `Quaternion.AngleAxis`. Copy // Rotate using the "up" direction as the axis until forward = targetVector CharacterActor.RotateYaw(targetVector); // Rotate a given amount (degrees) using the "up" direction as the axis CharacterActor.RotateYaw(amount); // Rotate around a pivot a given amount (degrees) using the "up" direction as the axis CharacterActor.RotateYaw(amount, pivot); // Rotate a given amount (degrees) using the "right" direction as the axis CharacterActor.RotatePitch(amount); // Rotate a given amount (degrees) using the "forward" direction as the axis CharacterActor.RotateYaw(amount); [](#id-2d-characters) 2D Characters ---------------------------------------- The 2D world is very different from the 3D world, especially regarding rotations. However, **all of the principles and functions mentioned above apply here as well.** The big difference between 2D and 3D is that `transform.forward` must be either `Vector3.forward` or `Vector3.back`. Otherwise, the collider size will get reduced. The `Forward` direction (actor property) is directly represented by `transform.right`. [PreviousMove the character](/ccp/how-to.../core/move-the-character) [NextLeave grounded state (e.g. jump)](/ccp/how-to.../core/leave-grounded-state-e.g.-jump) Last updated 2 years ago ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MPWzN86dj4gvbHHrwNM%252F-MPX0J7sz9q4XuDNJ5O6%252Fimagen.png%3Falt%3Dmedia%26token%3D0520ec92-ab6b-4e9c-a2ff-568041b3ab5b&width=768&dpr=4&quality=100&sign=58cb295&sv=2) --- # Use the character information (with examples) | Character Controller Pro (1.4.x) 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) Grounded state --------------------------------------- Copy if (CharacterActor.IsGrounded) { DoGroundLogic(); } [](#wall-collision-example) 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: Copy if (CharacterActor.WallCollision) { // Do wall collision logic. } [](#wall-running-behavior) Wall running behavior ----------------------------------------------------- Copy if (!CharacterActor.IsGrounded && CharacterActor.WallCollision) { // Do grounded logic. } [](#slide-movement) 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. Copy 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: Copy if (!CharacterActor.IsStable && CharacterActor.IsGrounded) { // Do Slide } We can simplify this condition by using the _CurrentState_ property from the actor (for more information please read the [States](/ccp/fundamentals/untitled/character-actor/stability#states) section). Copy 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_). Copy if (CharacterActor.CurrentState == CharacterActorState.UnstableGrounded) { if (CharacterActor.GroundedTime >= 1f) { // Do Slide } } Making the character slide is very simple. Based on [this](/ccp/fundamentals/untitled/character-actor/stability#stability) 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). So, this is the final code: Copy if( CharacterActor.CurrentState == CharacterActorState.UnstableGrounded ) { if( CharacterActor.GroundedTime >= 1f ) { CharacterActor.Velocity += - CharacterActor.Up * slideAcceleration * Time.deltaTime; } } [PreviousDisable collisions (ghost)](/ccp/how-to.../core/disable-collisions-ghost-character) [NextUse root motion](/ccp/how-to.../core/use-root-motion) Last updated 4 months ago --- # Use root motion | Character Controller Pro (1.4.x) [PreviousUse the character information (with examples)](/ccp/how-to.../core/use-the-character-information) [NextDetect a character using a "detector"](/ccp/how-to.../core/detect-a-character-using-a-detector) Last updated 2 years ago By using root motion you can switch from script-based movement to animation-based movement. For more information about what root motion is please visit [this link](https://docs.unrealengine.com/en-US/AnimatingObjects/SkeletalMeshAnimation/RootMotion/index.html) . Root motion can be enabled/disabled at any time by calling the _**useRootMotion**_ property from the `CharacterActor` component. Copy CharacterActor.UseRootMotion = true; In Addition, it is possible to tweak the way position and rotation get updated by root motion. For example, you can mix animation-based movement with script-based rotation. Do you want to apply root motion for planar movement but at the same time use script-based vertical movement (e.g. gravity, jumping, etc)? No problem, choose the _Set Planar Velocity_ option from the _Root Motion Velocity Type_ field. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LvxVSjyzvP6F7c9h_Hu%252Fuploads%252FtILh5JGXoACDFhqfwFeC%252Fimage.png%3Falt%3Dmedia%26token%3Dfdc1cb3d-313c-473a-a430-f3f4bea4611b&width=768&dpr=4&quality=100&sign=1d07003f&sv=2) --- # Character brain | Character Controller Pro (1.4.x) [PreviousCharacter state](/ccp/fundamentals/implementation/character-state) [NextCore](/ccp/how-to.../core) Last updated 1 year ago `CharacterBrain` is a component responsible for handling all character actions, regardless of whether they come from the player or not. If you are familiar with the Unity's "new" input system, you probably know what an action is. An **action** is just a link between an input signal (e.g. press the jump button) and an output result at the gameplay level (e.g. jump). All the available actions are predefined in a structure and then updated by the _CharacterBrain_ component at runtime. This approach create a level of abstraction between the inputs (GetKey, GetButton, etc.) and the character actions themselves (jump, move forward, etc.). [](#actions) Actions ------------------------- ### [](#types) Types CCP's Implementation supports three types of actions Action type Description BoolAction A toggle, this action can be pressed or not pressed. FloatAction A 1D Value from -1 to 1 (similar to `GetAxis`from Unity) Vector2Action A 2D Value from, basically a combination of two axis. Note that the BoolAction value is true or false (a bool). If you need to know if that action was "started" or "canceled" (e.g. was the jump button pressed?), you need to get the **Started** or **Canceled** property respectively. ### [](#character-actions-struct) Character actions struct These actions are predefined and grouped together inside a struct. Each public field represents a particular action. Copy public struct CharacterActions { // Bool actions public BoolAction @jump; public BoolAction @run; public BoolAction @interact; public BoolAction @jetPack; public BoolAction @dash; public BoolAction @crouch; //... } You can visualize the actions values in runtime in the inspector (Human or AI). CCP includes a _ScriptableObject_ asset whose only job is to modify this _CharacterAction_ struct. The actions included by default were generated using the **Default Character Actions** asset. Have in mind that adding/removing actions might affect the scripts from the Demo content since these scripts are using the default CCP actions. [](#brain-types) Brain types --------------------------------- ### [](#human-brain) Human brain If the brain is set to _Human_, actions will get updated based on input devices (keyboard, mouse, joystick, UI, etc). The component responsible for this is called `InputHandler`, and it must be implemented specifically for each input system needed. By default, the brain allows the user to use two input handlers that come with the asset, or a custom one. Human input type Description Unity Input Manager It reads input data directly from Unity's Input manager (old system). UI\_Mobile It looks for all UI-based input components in the scene (`InputAxes` and `InputButton`). These components are responsible for converting UI events into input values. Custom An `InputHandler` custom implementation. ### [](#ai-brain) AI brain In this mode, the brain defines actions through code by using a `AIBehaviour`. Representation of the Human, the AI and the brain. Brain modes in the inspector. Available human input types. Example: AI behaviour using a sequence behaviour (Demo content). ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvyOLIKJOklGJLWNsA%252F-LyvyU4_UOLc_8FnvyqT%252FBrainModes.png%3Falt%3Dmedia%26token%3Ddaba0ce2-f503-45c6-b752-a7b961ae833b&width=768&dpr=4&quality=100&sign=4629dd96&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-LyvxXmZLQz0JRCLXEnJ%252F-LyvyGGzsu0oWoJmo2L2%252FcharacterBrain.png%3Falt%3Dmedia%26token%3Da91c280f-944d-4673-8fca-682bc2c8c4fd&width=768&dpr=4&quality=100&sign=17333b82&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-M9XyFr6IuU2qH8yusG3%252F-M9XymHujl37cCNo7c1a%252Fimagen.png%3Falt%3Dmedia%26token%3D16f32fd0-48e3-4b02-9aa6-49e85813e6ef&width=768&dpr=4&quality=100&sign=3960588a&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-M9XseN2KHG4sQTj8tHQ%252F-M9XxMD9oNUuUDT2O0bW%252Fimagen.png%3Falt%3Dmedia%26token%3D5ff9b6cb-8ebb-4b7e-898b-9d1687027218&width=768&dpr=4&quality=100&sign=6f65302f&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Lyvyk-QSFwCh-EefBag%252F-LyvzZqtEL2gctckzZ5f%252FhumanInputType.png%3Falt%3Dmedia%26token%3D5251962e-c591-442c-bde2-58e212e81334&width=768&dpr=4&quality=100&sign=b308f77d&sv=2) --- # Implementation | Character Controller Pro (1.4.x) [Organize the character hierarchy](/ccp/how-to.../implementation/organize-the-character-hierarchy) [States](/ccp/how-to.../implementation/states) [Actions](/ccp/how-to.../implementation/actions) [PreviousAdd a dynamic one way platform](/ccp/how-to.../core/add-a-dynamic-one-way-platform) [NextOrganize the character hierarchy](/ccp/how-to.../implementation/organize-the-character-hierarchy) --- # States | Character Controller Pro (1.4.x) [Add and configure the state machine](/ccp/how-to.../implementation/states/add-and-configure-the-state-machine) [Create a state](/ccp/how-to.../implementation/states/create-a-state) [Transition from one state to another](/ccp/how-to.../implementation/states/transition-from-one-state-to-another) [Handle animation](/ccp/how-to.../implementation/states/add-animation-to-a-state) [Modify an IK (inverse kinematics) element](/ccp/how-to.../implementation/states/modify-an-ik-element) [PreviousOrganize the character hierarchy](/ccp/how-to.../implementation/organize-the-character-hierarchy) [NextAdd and configure the state machine](/ccp/how-to.../implementation/states/add-and-configure-the-state-machine) Last updated 3 years ago --- # Actions | Character Controller Pro (1.4.x) [Define your own actions](/ccp/how-to.../implementation/actions/define-your-own-actions) [Use the character actions](/ccp/how-to.../implementation/actions/use-the-character-actions) [Use a custom Input Handler](/ccp/how-to.../implementation/actions/use-a-custom-input-handler) [Use the new input system](/ccp/how-to.../implementation/actions/use-the-new-input-system) [Create your own AI movement logic](/ccp/how-to.../implementation/actions/create-your-own-ai-logic) [PreviousModify an IK (inverse kinematics) element](/ccp/how-to.../implementation/states/modify-an-ik-element) [NextDefine your own actions](/ccp/how-to.../implementation/actions/define-your-own-actions) Last updated 3 years ago --- # Add a static one way platform | Character Controller Pro (1.4.x) [PreviousDetect a character using a "detector"](/ccp/how-to.../core/detect-a-character-using-a-detector) [NextAdd a dynamic one way platform](/ccp/how-to.../core/add-a-dynamic-one-way-platform) Last updated 3 years ago [](#id-1.-create-a-new-layer) 1\. Create a new layer --------------------------------------------------------- In order to define a one way platform you need to create a dedicated layer mask: [](#id-2.-create-your-platform) 2\. Create your platform ------------------------------------------------------------- A platform needs to have a collider component on it. [](#id-3.-assign-the-one-way-platform-layer) 3\. Assign the "one way platform" layer ----------------------------------------------------------------------------------------- Assing the layer from step 1 to your platform object Here's an example of a static 3D one way platforms: ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Mihw-OiABV0FMRwFJFH%252F-MihwsPdmamRSseUOhsG%252Fimagen.png%3Falt%3Dmedia%26token%3Df23459da-98df-4d39-9f0a-dac7d3954a84&width=768&dpr=4&quality=100&sign=70b8a6e1&sv=2) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MihrLRk3Zsl86z3mAvu%252F-Mihrmaul5bjt8RGLLxy%252Fimagen.png%3Falt%3Dmedia%26token%3D66c0477e-e4d8-4f85-9367-459c0b5cc652&width=768&dpr=4&quality=100&sign=5d278eb7&sv=2) --- # Organize the character hierarchy | Character Controller Pro (1.4.x) [PreviousImplementation](/ccp/how-to.../implementation) [NextStates](/ccp/how-to.../implementation/states) Last updated 4 years ago The main rule is: **CharacterBody and CharacterActor should always be in the root object (the "character" object).** You can be creative with the rest of the components. The demo characters use the following hierarchy: Root Contains _**CharacterBody**_ and _**CharacterActor**_ Graphics Contains the **visual elements** of the character, from sprites to animated 3D meshes. States Contains the _**CharacterStateController**_ and every _**CharacterState**_ related to the character Actions Contains the _**CharacterBrain**_ and all the _**AIBehaviours**_ (AI characters). Environment Contains the _**MaterialController**_ (used by some of the states included in the Demo) ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-MA7oDdGet1MsRLZGHdW%252F-MA7o_GIoYaiBEzg5zjJ%252Fimagen.png%3Falt%3Dmedia%26token%3D4e322bd7-b92c-48bb-8614-ec314e9fb394&width=768&dpr=4&quality=100&sign=cd4dd78f&sv=2) --- # Use a custom Input Handler | Character Controller Pro (1.4.x) The brain offers three human input modes: * Unity's Input Manager (old) * UI * Custom The `custom` mode, as the name implies, allows you to use a custom input handler. For this, you will need to: 1. Create a custom class that derives from the _InputHandler_ abstract class. 2. Implement its abstract methods using the input system API. 3. Add the component created (1.) somewhere in the scene. 4. Go to CharacterBrain and change the Human input type to "Custom". 5. Drag & drop the input handler component (3.) into the input handler field (CharacterBrain). [](#creating-the-class) Creating the class ----------------------------------------------- Plain and simple C#. Copy public class CustomInputHandler : InputHandler { public override bool GetBool(string actionName) { return SomeInputSystem.GetButton(actionName); } public override float GetFloat(string actionName) { return SomeInputSystem.GetAxis(actionName); } public override Vector2 GetVector2(string actionName) { return SomeInputSystem.GetVector2(actionName); } } For example, this is the default _UnityInputHandler_ (Unity's Input Manager) that comes with the asset. Copy public class UnityInputHandler : InputHandler { public override bool GetBool(string actionName) { return Input.GetButton(actionName); } public override float GetFloat(string actionName) { return Input.GetAxis(actionName); } public override Vector2 GetVector2(string actionName) { // Not officially supported by Unity return new Vector2( Input.GetAxis( actionName + " X" ) , Input.GetAxis( actionName + " Y" ) ); } } [PreviousUse the character actions](/ccp/how-to.../implementation/actions/use-the-character-actions) [NextUse the new input system](/ccp/how-to.../implementation/actions/use-the-new-input-system) Last updated 1 year ago --- # Add a dynamic one way platform | Character Controller Pro (1.4.x) [PreviousAdd a static one way platform](/ccp/how-to.../core/add-a-static-one-way-platform) [NextImplementation](/ccp/how-to.../implementation) Last updated 2 years ago The process is very similar as the one for static one way platforms. However, there are a few important things to consider: [](#id-1.-create-a-static-one-way-platform) 1\. Create a static one way platform ------------------------------------------------------------------------------------- (follow [these instructions](/ccp/how-to.../core/add-a-static-one-way-platform) ). [](#id-2.-add-a-rigidbody) 2\. Add a Rigidbody --------------------------------------------------- Add a Rigidbody (Rigidbody2D) component to the platform. One way platforms should be kinematic, **make sure to enable the isKinematic property**. [](#id-3.-add-a-dynamiconewayplatform-component) 3\. Add a DynamicOneWayPlatform component ----------------------------------------------------------------------------------------------- This component is responsible for re-simulating the platform physics and detecting multiple characters (using a BoxCast). It will automatically detect the BoxCollider component (whether is 2D or 3D) and Rigidbody component (whether is 2D or 3D). The component itself exposes a layer mask that should be used to filter the collision results. Make sure to specify all the layers with characters on them (or leave it like that, "Everything" is set by default). Here's an example of a dynamic 3D one way platform (with no movement behaviour). [](#id-4.-make-it-move) 4\. Make it move --------------------------------------------- Once you have everything set up, it is time to add the movement behaviour. You can choose whatever method you want, using a custom script, using CCP's platform behaviours (e.g. ActionBasedPlatform), etc. ![](https://lightbug14.gitbook.io/~gitbook/image?url=https%3A%2F%2F3428853154-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-LvxVSjyzvP6F7c9h_Hu%252F-Mihw-OiABV0FMRwFJFH%252F-MihwEx0wECVdS5wwUBy%252Fimagen.png%3Falt%3Dmedia%26token%3D4522d314-0e28-4b1b-ac42-53b5aa4ada77&width=768&dpr=4&quality=100&sign=d81b835c&sv=2) --- # Transition from one state to another | Character Controller Pro (1.4.x) [](#one-state) One state ----------------------------- Let's say you want to go from _**StateA**_ to _**StateB**_ if _**someCondition**_ is valid. For this you need to implement the CheckExitTransition in StateA (since you want to leave this state): Copy // StateA.cs -------------------------- public override bool CheckExitTransition() { if( someCondition ) { // Add StateB to the queue CharacterStateController.EnqueueTransition(); } } If someCondition is true, then StateB will have to handle the transition. To control the result you'll need to implement the _**CheckEnterTransition**_ in StateB. By default the _CheckEnterTransition_ will accept the transition (returning true). Let's say StateB can be entered only from StateA: Copy // StateB.cs -------------------------- public override bool CheckEnterTransition( CharacterState fromState ) { // True if fromState is StateA. False otherwise if( fromState == CharacterStateController.GetState() ) return true; return false; } [](#multiple-states) Multiple states ----------------------------------------- Let's say you have two or more states that can be triggered by the same initial condition (_someCondition_ from the previous example). Both uses the same condition, but the target state has some extra conditions as well (_CheckEnterTransition_). If you need to evaluate multiple states you can enqueue them, one after another. Copy // StateA.cs -------------------------- public override bool CheckExitTransition() { if( someCondition ) { CharacterStateController.EnqueueTransition(); CharacterStateController.EnqueueTransition(); } } [PreviousCreate a state](/ccp/how-to.../implementation/states/create-a-state) [NextHandle animation](/ccp/how-to.../implementation/states/add-animation-to-a-state) Last updated 4 years ago ---