Skip to main content

FaceTarget

A class in Root.Township, Alta.Intelligence.

Component that turns a creature's head bone toward its current target, within a maximum angle, and syncs the head rotation to clients. The server drives it; nothing in code calls it, so prefab events probably do.

Constructors​

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

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerStatic profiling counter shared by every FaceTarget.
static AccumulativeAverageCount serializeTimerStatic profiling counter shared by every FaceTarget.
10 private and internal fields
MemberWhat it is
private Agent agentThe creature whose target is faced.
private Quaternion currentRotationThe head's local rotation as last set by this component.
private Transform headThe bone that is rotated.
private bool isYFacingBackFlips the look direction, for head bones whose forward axis points backwards.
private float maxAngleMost the head may turn from its rest rotation, in degrees (default 45).
private Quaternion originalRotationThe head's rest local rotation, captured in the editor.
private float rotationSpeedTurn speed in degrees per second (default 10).
private Quaternion serverRotationRotation being sent, or on clients the last rotation received.
private IUnityUpdateMethod updateFaceThe registered LateUpdate method currently running (facing, easing back, or remote), or null.
private static UpdateModule updateModuleShared LateUpdate module named "Agent Face Target" that runs every head update.

Properties​

3 private and internal properties
MemberWhat it is
private int Alta.Networking.INetworkSerialized.MaximumBits { get; }32 bits per sync: the compressed head rotation.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Shared profiling counter for PrepareForWrite.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Shared profiling counter for Serialize.

Methods​

MemberWhat it is
void SetActiveServer(bool isFacing)Server: starts facing the target if true, otherwise eases the head back to rest.
void StartFacing()Starts turning the head toward the target each LateUpdate, if the agent has a target and isn't already facing.
void StopFacing(bool isAnimatingBack)Stops the facing update, optionally starting an ease back to the rest rotation.
8 private and internal methods
MemberWhat it is
private void FacePosition(Vector3 position)Rotates the head toward a world position, clamped to maxAngle from its rest rotation and limited to rotationSpeed degrees per second.
private void OnDestroy()Stops the facing update without easing back.
private void OnValidate()Editor: stores the head's current local rotation as originalRotation.
private bool Alta.Networking.INetworkSerialized.PrepareForWrite(bool isWriteFull)Copies the current head rotation for sending. Delta writes only go out while a head update is running.
private void Alta.Networking.INetworkSerialized.Serialize(Stream stream, bool isWriteFull)Sends the head rotation. On clients a full write snaps the head, a delta write starts easing toward it.
private void UpdateFace()Per-frame update while facing: follows the target, or eases back once the agent has none.
private void UpdateFaceBack()Per-frame update that turns the head back to rest and stops when within 1 degree.
private void UpdateRemoteFace()Client: per-frame update that eases the head to the rotation the server sent, then stops.