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
  • 3D Characters
  • Assigning a Rotation
  • Setting a direction property
  • Using the actor public methods
  • 2D Characters
  1. How to...
  2. Core

Rotate the character

3D Characters

Assigning a Rotation

Same as transform.rotation, you can set the Rotation property directly using any Quaternion value you want.

CharacterActor.Rotation = SomeQuaternion;

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):

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

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.

// 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);

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 characterNextLeave grounded state (e.g. jump)

Last updated 2 years ago