> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinemation.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Character Camera: First and Third-Person Camera Setup

> Reference guide for the CAS Character Camera — first-person mode, third-person offsets, camera shakes, smooth FOV transitions, and collision avoidance.

The **Character Camera** component is a self-contained camera controller that ships with the Character Animation System. It handles first-person and third-person perspective switching, applies stabilization in first-person mode to smooth out animation jitter, plays procedural camera shakes for hit feedback and recoil, and supports smooth FOV transitions for aiming or sprinting. Add the component to your camera's parent GameObject and wire up the input and transform references to get started.

## Features

* **First- and third-person views** — toggle freely between perspectives at runtime.
* **Camera stabilization** — first-person mode dampens the camera against skeleton movement to reduce swimming artifacts.
* **Camera shakes** — procedural fire-and-forget shakes driven by random ranges on each axis.
* **Smooth FOV updates** — interpolated field-of-view changes for aiming, sprinting, and other states.

## Input Properties

These properties feed the camera with gameplay data each frame. Set them from your character controller script.

<ParamField path="Yaw Input" type="float">
  Horizontal rotation input — typically mapped to the horizontal mouse axis or right analog stick X. Drives left–right camera rotation.
</ParamField>

<ParamField path="Pitch Input" type="float">
  Vertical rotation input — typically mapped to the vertical mouse axis or right analog stick Y. Drives up–down camera rotation.
</ParamField>

<ParamField path="Is Aiming" type="bool">
  Set to `true` when the player is aiming. The camera uses this value to select the correct Offset struct (aiming offsets) and can also trigger FOV changes.
</ParamField>

<ParamField path="Is Crouching" type="bool">
  Set to `true` when the player is crouching. The camera reads this to apply the crouch-specific Offset values, lowering the camera to match the crouched stance.
</ParamField>

<ParamField path="Is First Person" type="bool">
  Defines the active view mode. When `true`, the camera follows the **First Person Socket** transform and stabilization is active. When `false`, the camera uses the third-person offset configuration.
</ParamField>

<ParamField path="Use Right Shoulder" type="bool">
  Determines the shoulder anchor in third-person mode. Set to `true` for a right-shoulder view and `false` for a left-shoulder view. Toggle this at runtime to let players switch sides.
</ParamField>

<ParamField path="View Smoothing" type="float">
  The interpolation speed used when smoothing camera rotation. Higher values produce snappier, more responsive camera movement; lower values create a floating, cinematic feel.
</ParamField>

## Transform Properties

<ParamField path="First Person Socket" type="Transform">
  The transform that the camera follows when **Is First Person** is `true`. Assign the head bone, a dedicated camera socket bone, or any child transform positioned at eye level on your character. If this is left unassigned, the camera will default to the world origin, placing it at the character's feet. See [Camera appears at the character's feet](/cas/guides/troubleshooting#camera-appears-at-the-characters-feet-in-first-person-view) for the fix.
</ParamField>

<ParamField path="Camera Animation Source" type="Transform">
  An animated transform whose motion is applied to the camera for procedural sway and weapon-bob effects. This is typically a bone or an empty GameObject that is driven by the animation system to add life to the camera in both first- and third-person modes.
</ParamField>

## Offset Properties

Camera offsets are grouped into structs, one per gameplay situation. Each struct has two fields:

<ParamField path="Offset" type="Vector3">
  Position offset applied relative to the **Pivot** point. Use this to nudge the camera forward, backward, or vertically within a given scenario.
</ParamField>

<ParamField path="Pivot" type="Vector3">
  The pivot point offset relative to the player transform's origin. Adjusting the pivot shifts where the camera orbits in third-person mode, or where it anchors in first-person mode.
</ParamField>

<Tip>
  The Character Camera uses the player's root transform as the world origin for all offset calculations. Offsets are applied additively on top of the socket transform in first-person mode.
</Tip>

The available offset scenarios are:

| Scenario          | When it is used                               |
| ----------------- | --------------------------------------------- |
| Default Standing  | Player is upright, not aiming, third-person   |
| Default Crouching | Player is crouching, not aiming, third-person |
| Aiming Standing   | Player is upright and aiming, third-person    |
| Aiming Crouching  | Player is crouching and aiming, third-person  |
| First Person      | Any first-person state                        |

## Camera Collision

The collision system traces a sphere from the player toward the camera each frame and pulls the camera forward if the trace hits an obstacle, preventing it from clipping into walls and geometry.

<ParamField path="Trace Radius" type="float">
  The radius of the sphere used for the collision trace. Increase this value if the camera clips through thin walls or narrow geometry; decrease it for tighter offset behavior near obstacles.
</ParamField>

<ParamField path="Trace Interp Speed" type="float">
  The speed at which the camera smoothly adjusts its distance when collision is detected or cleared. Higher values make the camera snap quickly to the safe position; lower values produce a gradual glide.
</ParamField>

<ParamField path="Trace Mask" type="LayerMask">
  The physics layers included in the collision trace. Assign the layers that represent solid world geometry (walls, floors, props). Exclude layers such as characters, triggers, and water to prevent unintended collision responses.
</ParamField>

## FOV API

Call the following method to update the camera's target field of view at runtime. The camera interpolates smoothly from the current FOV to the target value each frame:

```csharp theme={null}
// Smoothly transitions the camera to a new target FOV.
characterCamera.SetTargetFOV(float targetFOV);
```

A typical usage pattern is to call `SetTargetFOV` in response to the aiming input:

```csharp theme={null}
public void OnAim(bool isAiming)
{
    float targetFOV = isAiming ? aimFOV : defaultFOV;
    _characterCamera.SetTargetFOV(targetFOV);
}
```

## Camera Shakes

Camera shakes are fire-and-forget procedural motions that add impact feedback for events such as weapon recoil, explosions, or landing. Each shake asset defines the motion range per axis and how quickly it decays.

### Shake Asset Properties

<ParamField path="X" type="Vector4">
  Pitch/Yaw/Roll ranges for motion around the **X axis**. The shake system picks a random value between `Mathf.Random(range.x, range.y)` for the outgoing swing and `Mathf.Random(range.z, range.w)` for the return swing.
</ParamField>

<ParamField path="Y" type="Vector4">
  Pitch/Yaw/Roll ranges for motion around the **Y axis**, using the same four-component range format as X.
</ParamField>

<ParamField path="Z" type="Vector4">
  Pitch/Yaw/Roll ranges for motion around the **Z axis**, using the same four-component range format as X.
</ParamField>

<ParamField path="Pitch / Yaw / Roll" type="Vector4">
  Per-axis angular range values. The `x` and `y` components define the minimum and maximum of the forward swing; the `z` and `w` components define the minimum and maximum of the return swing.
</ParamField>

<ParamField path="Play Rate" type="float">
  Playback speed multiplier for the shake. Values above `1.0` produce a faster, snappier shake; values below `1.0` produce a slower, heavier feel.
</ParamField>

<ParamField path="Smooth Speed" type="float">
  The interpolation speed used when blending the shake motion. Higher values give the shake a sharper, more immediate onset; lower values create a rolling, sustained feel.
</ParamField>

<Tip>
  A shake value is sampled as two random draws: the outgoing displacement uses `Random(range.x, range.y)` and the return displacement uses `Random(range.z, range.w)`. Setting both pairs to the same values produces a consistent shake; widening the gap creates more varied, organic results.
</Tip>

### Playing a Shake from Code

Call `PlayCameraShake` on your `CharacterCamera` reference to trigger a shake asset at runtime:

```csharp theme={null}
[SerializeField] private CameraShakeAsset recoilShake;
private CharacterCamera _characterCamera;

private void Start()
{
    _characterCamera = GetComponentInChildren<CharacterCamera>();
}

private void OnFireWeapon()
{
    // Play the recoil shake every time the weapon fires.
    if (_characterCamera != null)
    {
        _characterCamera.PlayCameraShake(recoilShake);
    }
}
```

<Note>
  Camera shakes are fully additive — you can call `PlayCameraShake` multiple times in quick succession (for example, on automatic fire) and the shakes will stack and blend together naturally.
</Note>
