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 : CharacterComponentInheritance: ParagonObject → ParagonComponent<Character> → CharacterComponent → CharacterCamera
Remarks
CharacterCamera wraps a CinemachineCamera (Unity Cinemachine v3) attached to the character prefab. It serves multiple roles:
Camera control — Activate/deactivate camera priority for this character (used when possessing/unpossessing characters)
Look direction — Provides
Position,Rotation,Directionfor other systems to query where the character is lookingHead IK — Hooks into the Animator's IK pass to orient the character's head toward the camera's forward direction
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
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.
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.
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.
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
CinemachineCamera must be a child of the character prefab
OnInitialize() searches via GetComponentInChildren<CinemachineCamera>(true). If the camera is not a child of the character hierarchy, initialization will fail with a NullReferenceException.
CinemachineInputAxisController required on camera GameObject
The input controller is fetched from the same GameObject as the CinemachineCamera. If it's missing, inputAxisController will be null and Activate()/Deactivate() will throw.
Raycast hits all layers
The Raycast() method uses a default Physics.Raycast with no layer mask or max distance. This may detect unintended objects (triggers, terrain, UI blockers). Consider whether layer filtering is needed for your use case.
See Also
CharacterComponent — base class for all character services
ParagonComponent<T> — generic component base class
Last updated