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.
- Listed in Global namespace: A to B
- Inherits or implements
MonoBehaviour - Attributes
ExecuteInEditMode
Constructors
| Member | What it is |
|---|---|
AlwaysFacePlayer() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
6 private and internal fields
| Member | What it is |
|---|---|
private Vector3 defaultLocal | Local position captured in Awake, restored every update. |
private float interpolation | Lerp factor per update towards the target rotation (0.5 by default). |
private Quaternion oldRotation | Rotation from the previous update, the start of the next lerp. |
private Quaternion rotationOffset | Extra rotation applied after looking at the player. |
private IUnityUpdateMethod update | Handle for the registered update method. |
private static BudgetedUpdateModule updateModule | Shared budgeted module ("Look At Player", late update) that all instances register on. |
Methods
5 private and internal methods
| Member | What 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. |