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.
- Listed in Networking and servers
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
NetworkRotation() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
10 private and internal fields
| Member | What it is |
|---|---|
private float addRotationMultiplier | Scale applied to angles passed to RotateAngle (default 0.5). |
private Interactable baseInteractable | The interactable whose interaction ending triggers a sync. |
private IUnityUpdateMethod fixedUpdate | The registered fixed update lerp, or null. |
private float fixedUpdateLerpTime | Lerp factor per fixed update (default 0.5). |
private Vector3 localAxis | The normalized axis the rotation is around. |
private float precision | Step size used to pack the angle, and the close-enough distance for lerping. |
private float snapDistance | Angle difference above which a received value snaps instead of lerping (default 90). |
private MethodSyncStruct<float> syncStatus | Method sync that carries the angle. |
private Transform targetTransform | The transform being rotated (this object). |
private float value | The target angle last set or received. |
Properties
1 private and internal property
Methods
| Member | What 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
| Member | What 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. |