Skip to main content

NetworkRotation

A class in Root.Township, Alta.Networking.

Syncs an interactable's local rotation around one axis (for example a wheel or handle a player turns). The turning player's client sends the angle when the interaction ends; others lerp to it.

Constructors​

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

Fields​

10 private and internal fields
MemberWhat it is
private float addRotationMultiplierScale applied to angles passed to RotateAngle (default 0.5).
private Interactable baseInteractableThe interactable whose interaction ending triggers a sync.
private IUnityUpdateMethod fixedUpdateThe registered fixed update lerp, or null.
private float fixedUpdateLerpTimeLerp factor per fixed update (default 0.5).
private Vector3 localAxisThe normalized axis the rotation is around.
private float precisionStep size used to pack the angle, and the close-enough distance for lerping.
private float snapDistanceAngle difference above which a received value snaps instead of lerping (default 90).
private MethodSyncStruct<float> syncStatusMethod sync that carries the angle.
private Transform targetTransformThe transform being rotated (this object).
private float valueThe target angle last set or received.

Properties​

1 private and internal property
MemberWhat it is
private float CurrentValue { get; }The current angle around the axis, 0 to 360.

Methods​

MemberWhat it is
override void Initialize()Creates the angle method sync.
override void OnConnected(Player player)Sends the current angle to a newly connected remote player.
void RotateAngle(float angle)Turns by the given angle times addRotationMultiplier, locally only.
10 private and internal methods
MemberWhat it is
private void ApplyValue(float value)Sets the local rotation to the given angle around the axis.
private void Awake()Hooks the interactable's start and end events and reads the starting angle.
private float ClampValue(float value)Wraps an angle into the 0 to 360 range.
private void FinishLerp()Applies the target angle and stops the fixed update lerp.
private float GetDifference(float currentValue, float value)Difference between two angles, folded when over 180.
private void HandleRemote()Fixed update: lerps toward the synced angle, then finishes once within precision.
private float LerpToValue(float value, float lerpValue)Lerps the current angle toward the target, taking wrap-around into account.
private void SendSync(Interactable interactable, Interactor interactor)When a local interactor lets go, sends the current angle to everyone.
private void StopLerp(Interactable interactable, Interactor interactor)When an interaction starts, snaps to the target angle and stops lerping.
private void SyncStatus(IPlayer player, Stream stream, float syncValue)Sends or receives the angle. The server only accepts it from the last interacting player, then relays it to others.