Skip to main content

LookAtPlayer

A class in Root.Township, the global namespace.

Client: turns its object to face the local player's head every frame, smoothly, with an optional height adjustment.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private float backwardOffsetAims this far behind the head, along the head's forward.
private Transform cachedTransformThis object's transform.
private Vector3 defaultLocalLocal position the object returns to each frame before adjusting.
private float heightAdjustHow much of the height gap to the head the object moves by; 0 turns it off.
private float interpolationBlend factor per frame toward the target rotation.
private float maxHeightAdjustLargest upward height adjustment.
private float minHeightAdjustLargest downward height adjustment.
private Quaternion oldRotationRotation from the previous frame.

Methods​

4 private and internal methods
MemberWhat it is
private void Awake()Caches the transform, start local position and rotation.
private void LateUpdate()Blends toward facing the local player by interpolation.
private void OnEnable()Snaps to face the local player, or disables itself if there is none.
private Quaternion PositionAndGetRotation(PlayerController controller)Resets the local position, optionally moves it up or down toward head height, and returns the rotation facing the head.