Actor Controller

The Actor Controller is an advanced input-based character controller that replaces Unity’s standard character controller. While you can use it alone in any Unity 5 or Unity 2017 solution, it is also the foundation for the Motion Controller.

The Actor Controller is great for both PCs and NPCs . With its component based architecture, it can be used with any input solution and any AI solution.

 

Architecture

The Actor Controller has three core components:

Actor Controller – This is the Actor Controller component itself. Its a low-level component that knows how to collide with objects, apply gravity, and move, etc. It just doesn’t know when to move.

Actor Driver – This is a component (or other logic) that tells the Actor Controller when to move. You can use any of the drivers I’ve created, the Motion Controller (which is an advanced driver), or create your own driver.

Input Source – Typically a driver needs an input source. Sometimes it may use user input and sometimes it may use AI. This input component feeds the driver.

 

By using this approach, we can create any style of game-play with the responsiveness you need. You can use any input solution you want. You can also change how your actor moves (ie walking vs. flying) by changing how the Actor Driver directs the Actor Controller.

This also means that different characters in the same scene could be controlled in different ways or even by different players.

 

Setup

Setting up a character is really just a matter of placing a model in the scene and adding the Actor Controller component and an actor driver.

To setup a character with the Actor Controller, follow these setup steps.

 

Actor Drivers

Remember that the drivers that I’ve included are optional. These drivers handle basic movement cases and work for a variety of situations. However, you can also create your own driver to control the actor however you want.

In the end, the drivers are really just calling functions on the Actor Controller:


1
2
3
4
ActorController lActorController = gameObject.GetComponent<ActorController>();
lActorController.Move(new Vector3(0f, 0f, 1f));
lActorController.RelativeMove(new Vector3(0f, 0f, 1f));
lActorController.Rotate(Quaternion.Euler(0f, 90f, 0f));

Actor Driver

This is the default driver. It takes input from the keyboard, mouse, and Xbox controller and turns that into movement and rotation that is relative to the character’s forward direction. It then calls the Actor Controller functions to actually move the actor.

Animator Driver

Inherits from Actor Driver, but looks for a Unity Animator that is attached to the game object. If found, it will query for root-motion data and use that to move and rotate the character. If no root-motion data is found, input will be used to control the character.

Nav Mesh Driver

Inherits from Animator Driver, but uses a Nav Mesh Agent to move the actor to a specific target. If an Animator is found, it will query for root-motion data and use that to move and rotate the character. If no root-motion data is found, speed will be set on the component.

Sphere Actor Driver

Inherits from Actor Driver. When an “inner” sphere is found it will use this the actor’s body and rotate it based on the direction the character is moving. This give the impression that the sphere is rolling.

Spider Actor Driver

Inherits from Animator Driver. Similar to the other drivers, but when jump is pressed (and the actor is facing a wall), it will jump onto the wall so it can climb.

 

Body Shapes and Colliders

Body shapes are used for collision detection by the Actor Controller. By using spheres and capsules, we can represent the shape of a human as well as other non-simple characters. We also have the ability to change these shapes during run-time in order to match the character’s pose.

Rigidbodies

Adding a Rigidbody component to your character is fine. However, the rigidbody will attempt to control your character. So, that means the rigidbody and AC are competing. To fix this, disable gravity on the rigidbody and check the “Is Kinematic” check box. This will stop the rigidbody from trying to control your character.

 

Collisions vs. Grounding

“Colliding” and “Ground” are two different things.

Colliding means collision detection has determined you’ve bumped into another object… say a wall.

Grounding means we’ve tested the ground directly under the actor and they can stand on it.

So, you can completely disable collisions and your character will still be able to walk on the ground, move up slopes, etc. There is a huge performance boost when you disable collisions. This is great for NPCs that may be on rails or have limited movement.

Collisions

Actor Controller is able to collide against standard unity colliders. The fastest colliders are sphere, box, and plane. However, it can also detect collisions against mesh colliders. However, like Unity’s Character Controller, there’s a performance impact when colliding against mesh colliders.

With Unity 5.3, the AC is now using Unity’s non-allocating physics calls. This is great for mobile as collisions no longer create garbage that can cause performance blips. However, these calls cause collisions with back-faces of planes (and probably other shapes).

Collision & Grounding Layers

The Actor Controller uses standard Unity’s layers to determine what to collide with.
Simply set the layers in the collision section to collide with objects and props that are on the same layer.

If an object is on a layer that isn’t included in the Collision Layers, the character will simply go through the object.

To enable layers with grounding, you must also check the Use Grounding Layers checkbox.

Mesh Colliders

To help minimize the impact, we parse the mesh collider and store its information for future collisions. For small meshes, this can be done on first impact. However, for large meshes you’ll want the Actor Controller to preprocess the mesh collider.

To do this, add an ootii Mesh Partitioner component to the game object that has a Mesh Collider object. Then, check ‘Parse on Start’.

All the remaining options are for visualizing the partitions in the editor and should not be enable.

 

 

 

 

 

 

 

 

 

Component Details

To learn more about the Actor Controller component and its properties, go here.