Skip to main content

AlwaysFacePlayer

A class in Root.Township, the global namespace.

Client component that keeps an object turned towards the local player's head, smoothed, through a shared budgeted late-update module. Skips itself on a headless server.

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private Vector3 defaultLocalLocal position captured in Awake, restored every update.
private float interpolationLerp factor per update towards the target rotation (0.5 by default).
private Quaternion oldRotationRotation from the previous update, the start of the next lerp.
private Quaternion rotationOffsetExtra rotation applied after looking at the player.
private IUnityUpdateMethod updateHandle for the registered update method.
private static BudgetedUpdateModule updateModuleShared budgeted module ("Look At Player", late update) that all instances register on.

Methods​

5 private and internal methods
MemberWhat it is
private void Awake()Stores the starting local position and rotation.
private void OnDisable()Meant to stop the rotation update, but only deregisters when headless, so on a client the update probably keeps running after disable.
private void OnEnable()Client: snaps to face the current player and registers UpdateRotation on the budgeted module.
private Quaternion PositionAndGetRotation(PlayerController controller)Resets the local position to its default and returns a rotation looking at the player's HeadFollow, with rotationOffset applied.
private void UpdateRotation()Lerps from the last rotation towards facing the current player by interpolation.