Skip to main content

NetworkStarer

A class in Root.Township, the global namespace.

Makes a creature look at a target with its eyes, then its neck joints, and optionally turn its body. Staring and the target sync to clients.

Constructors​

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

Fields​

MemberWhat it is
NetworkStarer.ChangedState ChangedTurningCalled when body turning starts or stops.
NetworkStarer.ChangedDirection ChangedTurningDirectionCalled with the turn direction (1, -1, or 0 when stopped).
11 private and internal fields
MemberWhat it is
private float bodyDotWhenRotatingTurning stops once the facing dot reaches this value.
private bool isStaringBacking field for IsStaring.
private Transform leftEyeLeft eye transform.
private Quaternion leftEyeOriginalLocalTransformLeft eye's rest rotation.
private float maxEyeAngleFurthest an eye can turn from rest, in degrees.
private NetworkStarer.RotatingStructure neckChain of neck joints, each with its own angle limit.
private NetworkEntity networkTargetNetwork entity of the target, used to sync it.
private Transform rightEyeRight eye transform.
private Quaternion rightEyeOriginalLocalTransformRight eye's rest rotation.
private MethodSync syncSerializeMethod sync for the staring state.
private Transform targetBacking field for Target.

Properties​

MemberWhat it is
bool IsStaring { get; set; }Whether the creature is staring. Setting it sends the state and target to nearby chunks.
bool IsTurning { get; set; }Whether the body is turning toward the target. Set when the neck runs out of range.
Transform Target { get; set; }Transform to stare at. Setting it also finds its network entity for syncing.
float TurningSpeed { get; set; }Lerp factor per frame used while turning the body.

Methods​

MemberWhat it is
override void Initialize()Creates the sync message.
4 private and internal methods
MemberWhat it is
private void Awake()Stores the eyes' rest rotations and sets up the neck.
private void LateUpdate()Runs Stare while staring at a target.
private void Stare()Points the eye on the target's side at it, bending the neck when the eye can't reach and turning the body when the neck can't.
private void Sync(IPlayer player, Stream stream)Reads or writes the staring flag and target entity ID; a client stops staring if the target is missing.