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.
- Listed in Creatures and AI
- Inherits or implements
MonoBehaviour,INetworkSerialized
Constructors
| Member | What it is |
|---|---|
FaceTarget() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
static AccumulativeAverageCount prepareForWriteTimer | Static profiling counter shared by every FaceTarget. |
static AccumulativeAverageCount serializeTimer | Static profiling counter shared by every FaceTarget. |
10 private and internal fields
| Member | What it is |
|---|---|
private Agent agent | The creature whose target is faced. |
private Quaternion currentRotation | The head's local rotation as last set by this component. |
private Transform head | The bone that is rotated. |
private bool isYFacingBack | Flips the look direction, for head bones whose forward axis points backwards. |
private float maxAngle | Most the head may turn from its rest rotation, in degrees (default 45). |
private Quaternion originalRotation | The head's rest local rotation, captured in the editor. |
private float rotationSpeed | Turn speed in degrees per second (default 10). |
private Quaternion serverRotation | Rotation being sent, or on clients the last rotation received. |
private IUnityUpdateMethod updateFace | The registered LateUpdate method currently running (facing, easing back, or remote), or null. |
private static UpdateModule updateModule | Shared LateUpdate module named "Agent Face Target" that runs every head update. |
Properties
3 private and internal properties
| Member | What 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
8 private and internal methods
| Member | What 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. |