Skip to main content

BillboardToPlayer

A class in Root.Township, the global namespace.

Client component that turns an object to face the local player's head every late update, optionally smoothed. Removes itself on a headless server and pauses while the player is dead.

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private Transform cachedTransformThis object's transform.
private Transform cameraTransformThe player's camera transform. Stored but LateUpdate uses the head instead.
private bool hasCameraWhether a local player is set.
private float lerpSpeedSmoothing speed; 0 or less snaps instantly.
private Quaternion rotationSmoothed rotation carried between frames.
private Quaternion rotationOffsetExtra rotation applied after facing the player.

Methods​

MemberWhat it is
void SetRotationOffset(Quaternion offset)Sets the extra rotation applied after facing the player.
7 private and internal methods
MemberWhat it is
private void Awake()Destroys itself if headless; otherwise listens for the local player being set and starts tracking.
private float DeltaTime()Returns Time.deltaTime.
private Quaternion GetRotation(Transform cameraTransform)Rotation looking at the given transform with rotationOffset, lerped by lerpSpeed unless that's 0 or less.
private void LateUpdate()Faces the current player's Head.
private void OnDestroy()Unsubscribes from the player and death events.
private void PlayerKilled(DamageData damageData)Turns the billboard off when the local player dies.
private void UpdatePlayer(PlayerController player)Enables the component and subscribes to the player's death when there is one, or disables it when null.