Skip to main content

CameraStabelizer

A class in Root.Township, the global namespace.

Client: a second camera that follows the VR head with smoothing, for steadier recordings. Toggled with a key (Z by default); the on/off state is static.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private float angularStabilizationStrengthHow much of the old rotation is kept each frame, 0 to 1. Higher is smoother.
private Camera cameraThe camera that is turned on while stabilising.
private IKeyBoardTriggerHandler keyboardHandlerHandle for the registered toggle key, used to unregister it.
private float linearStabilizationStrengthHow much of the old position is kept each frame, 0 to 1. Higher is smoother.
private static Logger loggerNLog logger for this class.
private Transform targetTransformThe transform it follows, probably the player's head camera.
private Key toggleKeyKeyboard key that toggles the stabiliser. Default Z.
private IUnityUpdateMethod updateMethodHandle for the registered update method.

Properties​

MemberWhat it is
static bool IsActive { get; private set; }Whether the stabilised camera is on. Shared by all instances and kept across enable/disable.

Methods​

6 private and internal methods
MemberWhat it is
private void Activate()Registers the smoothing update, enables the camera and snaps it to the target.
private void Deactivate()Removes the smoothing update and disables the camera.
private void OnDisable()Unregisters the toggle key and deactivates the camera.
private void OnEnable()Registers the toggle key and turns the camera back on next frame if it was active.
private void StabelizeCamera()Per-frame update: lerps position and slerps rotation between the target and its current pose.
private void ToggleCamera(Key key)Key handler: flips IsActive, logs it and shows a message to the local player.