Skip to main content

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.

Constructors​

MemberWhat it is
CameraStabilization()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

10 private and internal fields
MemberWhat it is
private float angularStabilizationStrengthHow much of the previous rotation is kept each frame (0 to 1). Higher is smoother but laggier.
private Vector3 currentPositionThe smoothed camera position.
private Quaternion currentRotationThe smoothed camera rotation.
private HandCamera handCameraThe camera this smooths; its handles drive the target pose.
private int handCountHow many hands are holding the camera's handles.
private float linearStabilizationStrengthHow much of the previous position is kept each frame (0 to 1). Higher is smoother but laggier.
private Dictionary<Pickup, Vector3> offsetsEach handle's offset to the camera, in the handle's local space, taken in Awake.
private IUnityUpdateMethod stabilizationThe registered update method while the camera is held, or null.
private Transform targetTransformThe camera's transform, which this moves.
private static UpdateModule updateModuleShared late-update module that runs Stabilization.

Methods​

7 private and internal methods
MemberWhat 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.