CameraStabilization
A class in Root.Township, Alta.ScreenshotCamera.
Smooths the hand camera's movement while it is held, by lerping it towards its handles and following the player's locomotion. A component next to the HandCamera.
- Listed in Customization and screenshots
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
CameraStabilization() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
10 private and internal fields
| Member | What it is |
|---|---|
private float angularStabilizationStrength | How much of the previous rotation is kept each frame (0 to 1). Higher is smoother but laggier. |
private Vector3 currentPosition | The smoothed camera position. |
private Quaternion currentRotation | The smoothed camera rotation. |
private HandCamera handCamera | The camera this smooths; its handles drive the target pose. |
private int handCount | How many hands are holding the camera's handles. |
private float linearStabilizationStrength | How much of the previous position is kept each frame (0 to 1). Higher is smoother but laggier. |
private Dictionary<Pickup, Vector3> offsets | Each handle's offset to the camera, in the handle's local space, taken in Awake. |
private IUnityUpdateMethod stabilization | The registered update method while the camera is held, or null. |
private Transform targetTransform | The camera's transform, which this moves. |
private static UpdateModule updateModule | Shared late-update module that runs Stabilization. |
Methods
7 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Hooks each camera handle's grab and release events and records each handle's offset to the camera. |
private void EndStabilization(Interactable interactable, Interactor interactor) | Called when a handle is let go. Stops smoothing once no hands hold the camera, and resets the handle back in place as kinematic. |
private void LerpPositionAndRotation(Vector3 position, Quaternion rotation) | Moves the camera part of the way from its current pose to the target pose, using the two strength values. |
private void OnDestroy() | Removes the smoothing update if it is still registered. |
private void OnLocomotionMoved(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function) | Shifts (and on snap turns, rotates) the smoothed pose with the holder's locomotion so the camera does not lag behind a teleport or turn. |
private void Stabilization() | Per-frame update while held: aims at the midpoint of both handles, or the one held handle plus its offset, then lerps there. |
private void StartStabilization(Interactable interactable, Interactor interactor) | Called on a handle grab. On the first hand, stores the current pose, starts the update and subscribes to the holder's locomotion. |