Targeting

The Targeting module allows the camera to track targetable objects. This is commonly used for tracking enemies in action-adventure games. The system was designed after the targeting/tracking systems used in souls-like games, but it can be used in many different ways.


🎯 Settings

There's a lot of complexity to this system, so it is broken up into multiple submodules with their own unique settings.


Input

The input settings for camera targeting.

  • Lock On Button: The input button to toggle on/off target lock.

  • Require Hold: Requires the input button to be held down to continue targeting.


Locating

Locates targets within the camera's view.

  • Targetable Layers: The Unity layer(s) of the objects that can be targeted.

  • Radius: The maximum distance objects can be targeted from the camera.

  • Max Targets: The maximum amount of targets to locate within a single search (used for optimization purposes).


Look At

Rotates the camera to look at the current target.

  • Smoothing: How quickly the camera looks at the target. Larger numbers make the camera rotate more smoothly.

  • Max Speed: The max speed the camera can rotate to look at the target.


Line of Sight

Performs line of sight checks to determine if targets are visible.

  • Obstacles: The Unity layer(s) of the obstacles that can occlude the target.

  • Max Distance: The maximum distance the camera can see targets.

  • Out of Sight Time: The amount of seconds the target can remain out of sight before the camera stops targeting it. This is useful to ensure the camera does not stop targeting the object if it is occluded for only a brief second.

  • Update Interval: The amount of seconds between line of sight checks (used for optimization purposes).


Switching

Handles switching to new targets to the left or right of the current target and marks new targets as "sticky" so they cannot be switched from too quickly on accident.

  • Sticky Duration: The amount of seconds before another target can be switched to. This ensures targets are not switched to accidentally based on the sensitivity of the input device.

  • Input Sensitivity: The sensitivity multiplier applied to inputs to prevent switching targets too quickly.

  • Input Decay: The rate at which input values decay back to zero. The decay is used to force a quick input movement rather than a continuous slow movement.


Recentering

Resets the rotation of the camera to face the default forward direction when not targeting an object.

  • Recenter Time: The amount of seconds it takes the camera to recenter to the forward direction.

  • Max Speed: The max speed the camera can rotate to recenter.


User Interface

Displays UI while targeting objects, such as a small circle around the target.

  • Prefab: The UI content to instantiate.

  • Tracking: Changes the position of the UI content to track the target.


🧰 Scripting API