CharacterCamera

Manages a character's Cinemachine camera — activation/deactivation, look direction, IK-driven head look-at, and raycasting for the object the character is looking at.

Definition

Namespace: Paragon.Townskeep.CharacterSystem Assembly: Townskeep.dll

[Serializable]
public class CharacterCamera : CharacterComponent

Inheritance: ParagonObjectParagonComponent<Character>CharacterComponentCharacterCamera

Remarks

CharacterCamera wraps a CinemachineCamera (Unity Cinemachine v3) attached to the character prefab. It serves multiple roles:

  1. Camera control — Activate/deactivate camera priority for this character (used when possessing/unpossessing characters)

  2. Look direction — Provides Position, Rotation, Direction for other systems to query where the character is looking

  3. Head IK — Hooks into the Animator's IK pass to orient the character's head toward the camera's forward direction

  4. Look object detection — Performs a raycast each frame to detect what the character is looking at (used by the interaction system)

Camera Activation

When a character is possessed by a player, Activate() sets the Cinemachine camera priority to 99 and enables the CinemachineInputAxisController. When unpossessed, Deactivate() resets priority to 0 and disables input.

Quick Lookup

Goal
How

Activate camera for this character

camera.Activate()

Deactivate camera

camera.Deactivate()

Get camera forward direction

camera.Direction

Get camera world position

camera.Position

Get camera rotation

camera.Rotation

Force look at a point

camera.LookAt(worldPosition)

Force look in a direction

camera.LookTowards(direction)

Check if looking at something

camera.HasLookObject

Get what the camera sees

camera.LookObject

Access input controller

camera.InputAxisController

Properties

GameObject

The GameObject hosting the Cinemachine camera.

Position

The camera's corrected world-space position from the Cinemachine state.

Rotation

The camera's corrected world-space orientation from the Cinemachine state.

InputAxisController

The CinemachineInputAxisController for reading player look input.

Direction

The camera's forward direction vector (Rotation * Vector3.forward).

HasLookObject

Whether the camera's forward raycast is hitting a GameObject.

LookObject

The GameObject currently under the camera's center raycast, or null if nothing is hit.

Methods

OnInitialize (override)

Caches the Animator, CinemachineCamera, and CinemachineInputAxisController from the character prefab. Registers the OnAnimatorIK callback on the Animator.

circle-info

The CinemachineCamera is found with includeInactive = true, so disabled camera GameObjects will be discovered during initialization.

Activate

Sets the camera priority to 99 and enables the input axis controller. Call this when the player possesses this character.

Deactivate

Resets the camera priority to 0 and disables the input axis controller. Call this when the player unpossesses this character.

LookAt

Forces the camera to look at a specific world-space position.

Parameter
Type
Description

target

Vector3

World-space position to look at

LookTowards

Forces the camera to face a specific direction. No-ops if the direction is approximately zero.

Parameter
Type
Description

direction

Vector3

World-space direction to face

OnAnimatorIK

IK callback registered on the character's Animator. Sets full look-at weight and directs the character's head toward the camera's forward point.

Tick (override)

Called per-frame. Performs the forward raycast to detect the LookObject.

OnDebug (override)

Draws a debug ray from the camera position along the camera direction (10 units) when the character is spawned.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated