# Clamp Aim Target

The **Clamp Aim Target** node clamps a target position's pitch and yaw relative to a reference transform, keeping it within the character's valid range of motion. It includes hysteresis for the yaw boundary to prevent flickering, and a demo mode for visualizing the allowed range.

![Clamp Aim Target node](_media/clamp-aim-target-node.png ':size=1200')

## Usage

1. Add the **Clamp Aim Target** node to your Control Rig graph
2. Connect the raw aim **Target** (position in <span class="fr-term" tabindex="0" data-tooltip-key="global-space">global space</span>)
3. Connect the **Space** transform (typically the character's root or pelvis transform, defining the forward direction)
4. Configure **Pitch Range** and **Yaw Range** to match the character's range of motion
5. Use the **Result** output as the target for downstream aim nodes

Place this node **before** the Aim Chain or other aim nodes in your graph.

## Output Pins

| Pin | Type | Description |
|-----|------|-------------|
| Result | Vector | The clamped target vector in <span class="fr-term" tabindex="0" data-tooltip-key="global-space">global space</span> |

## Input Pins

| Pin | Type | Description |
|-----|------|-------------|
| Target | Vector | The target vector to clamp (usually in <span class="fr-term" tabindex="0" data-tooltip-key="global-space">global space</span>) |
| Space | Transform | The reference transform that defines the forward direction (X-axis) and local axes for pitch/yaw |
| Pitch Range | Range | The allowed range for pitch in degrees, relative to the Space X-axis (−90° to 90°) |
| Yaw Range | Range | The allowed range for yaw in degrees, relative to the Space X-axis (−180° to 180°, default: ±120°) |
| Hysteresis Threshold | float | The yaw angle threshold beyond which hysteresis is applied to prevent snapping when the target crosses the −180°/180° boundary behind the character. E.g. 150 means hysteresis activates when the absolute yaw exceeds 150°. Set to 180 to disable hysteresis. (90 to 180°, default: 150°) |
| Reset Hysteresis | bool | Reset the hysteresis state, allowing the side to be re-evaluated from scratch |
| Demo Mode | bool | When enabled, ignores the input target and instead animates the result to showcase the allowed pitch and yaw ranges |
| Debug | [Debug Settings](#debug-draw) | Debug visualization settings |

## Hysteresis

When the target crosses the ±180° yaw boundary, hysteresis prevents the clamped result from flickering between the two sides. The hysteresis threshold defines how far past the boundary the target must go before the clamped side switches.

![Hysteresis comparison](_media/clamp-aim-target-hysteresis-comparison.mp4 ':include :type=video autoplay loop muted playsinline')

## Demo Mode

Enable **Demo Mode** to animate the result through the full range of allowed pitch and yaw values. This is useful for previewing the clamping limits in the viewport without needing to move the actual target.

## Debug Draw

| Property | Type | Description |
|----------|------|-------------|
| Enabled | bool | Whether to draw debug visualization |
| Scale | float | Scale factor for debug visualization sizes |

Use this debug view in this order:

1. Check the yellow cone and boundary arcs to see the allowed range.
2. Check the yellow line and point to see the clamped result.
3. Check the orange overlays only when the target is being clamped or hysteresis is active.

| Debug item | Meaning |
|------------|---------|
| Yellow cone and boundary arcs | Allowed pitch and yaw range |
| Yellow line and point | Clamped aim target |
| Orange plane | Hysteresis boundary at the configured yaw threshold when hysteresis is active |
| Orange-red arc and point | Difference between the clamped result and the unclamped input target |
