Skip to main content

FaceObject

A class in Root.Township, the global namespace.

Rotates parts around an axis to follow the average position of the hands holding linked pickups, like a crank or lever. Looks like test code: it spawns a stray sphere in Start.

Constructors​

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

Fields​

4 private and internal fields
MemberWhat it is
private int lastInteractorCountHand count from the last midpoint, used to spot grab changes.
private bool needsToZeroSet when the grab changes so Advanced resets its last direction.
private RotationBucket[] partsToRotateParts to rotate, each with its pickups, axis and settings.
private GameObject spherePrimitive sphere created in Start, never used.

Methods​

8 private and internal methods
MemberWhat it is
private void Advanced(RotationBucket item)Rotates in local space around the axis towards the hands, with optional slerp, clamped to clampDegrees from identity.
private Quaternion ClampAroundIdentity(Quaternion rotation, float degrees)Limits a rotation to a number of degrees from identity.
private Vector3 GetMidPoint(Pickup[] pickups, Vector3 baseObjectPos)Averages the hand positions on the pickups, or returns the base position when none; flags a reset when the hand count crosses one.
private void OnDrawGizmosSelected()Draws each part's rotation axis.
private void OnValidate()Normalises each part's rotation axis.
private void Simple(RotationBucket item)Rotates the part around its world axis by the change in direction to the hands since last frame.
private void Start()Creates a small primitive sphere (unused), checks references and records the starting direction for each part.
private void Update()For each part, updates the tracked hand position and rotates it; logs and stops when no linked pickup has an interactors list.