Class ThirdPersonCharacterController
- Namespace
- CodeSmile.AnyMotion.AnimateYourself.Samples /
- Assembly
- ApiSource.dll
Third-person locomotion: a UnityEngine.CharacterController driven by the Input System, moving relative to the Cinemachine camera.
[RequireComponent(typeof(CharacterController))]
public sealed class ThirdPersonCharacterController : MonoBehaviour
Expand Details ...
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourThirdPersonCharacterController
Remarks
Four things about it are deliberate:
- It writes only the object it sits on. The gait drivers write the character's bones, which are below that object, so the two never write the same transform. Measured on 2026-08-23: with this component and the rig on one object, 120 steps of driving the gait changed the object's position by 0.0000 mm, its rotation by 0.0000 degrees and its scale by 0.0000, while the hips moved.
- It pushes its own measured planar speed into AnimateHumanoid instead of letting the gait guess. Cadence derives from speed, so a gait told the wrong speed takes steps at the wrong rate and the planted foot slides across the ground, however good the driver space is. It goes through AnimateHumanoid's own public properties rather than reaching into the components underneath, because sample code has to model what a customer can write.
- Look is not handled here. Cinemachine's own input axis controller reads it, so the camera keeps working when this component is disabled or replaced by the user's own controller — which is the normal case for a shipped asset.
- Strafing: holding the Strafe action faces the camera's own direction instead of the movement direction, and the signed angle between the two is pushed to MoveDirection every frame — the same "push the measured value, do not let the gait guess" reasoning as Move Speed above, since strafing is exactly the case Move Direction exists for: the body travelling one way while facing another.
Properties
IsGrounded
True while the controller is in contact with the ground.
public bool IsGrounded { get; }
Property Value
- bool
PlanarSpeed
Horizontal speed in metres per second, after smoothing. This is what the gait is told.
public float PlanarSpeed { get; }
Property Value
- float