NetworkRigidbody - syntax

This commit is contained in:
MrGadget1024 2022-12-22 02:33:31 -05:00
parent 0f013adc43
commit faede54e14

View File

@ -13,7 +13,6 @@ public class NetworkRigidbody : NetworkBehaviour
public bool clientAuthority = false;
[Header("Velocity")]
[Tooltip("Syncs Velocity every SyncInterval")]
[SerializeField] bool syncVelocity = true;
@ -23,9 +22,7 @@ public class NetworkRigidbody : NetworkBehaviour
[Tooltip("Only Syncs Value if distance between previous and current is great than sensitivity")]
[SerializeField] float velocitySensitivity = 0.1f;
[Header("Angular Velocity")]
[Tooltip("Syncs AngularVelocity every SyncInterval")]
[SerializeField] bool syncAngularVelocity = true;
@ -43,13 +40,11 @@ public class NetworkRigidbody : NetworkBehaviour
void OnValidate()
{
if (target == null)
{
target = GetComponent<Rigidbody>();
}
}
#region Sync vars
[SyncVar(hook = nameof(OnVelocityChanged))]
Vector3 velocity;
@ -84,7 +79,6 @@ void OnVelocityChanged(Vector3 _, Vector3 newValue)
target.velocity = newValue;
}
void OnAngularVelocityChanged(Vector3 _, Vector3 newValue)
{
if (IgnoreSync)
@ -124,32 +118,24 @@ void OnAngularDragChanged(float _, float newValue)
target.angularDrag = newValue;
}
#endregion
#endregion
internal void Update()
{
if (isServer)
{
SyncToClients();
}
else if (ClientWithAuthority)
{
SendToServer();
}
}
internal void FixedUpdate()
{
if (clearAngularVelocity && !syncAngularVelocity)
{
target.angularVelocity = Vector3.zero;
}
if (clearVelocity && !syncVelocity)
{
target.velocity = Vector3.zero;
}
}
/// <summary>
@ -231,9 +217,7 @@ void SendVelocity()
// only update syncTime if either has changed
if (angularVelocityChanged || velocityChanged)
{
previousValue.nextSyncTime = now + syncInterval;
}
}
[Client]
@ -289,10 +273,9 @@ void CmdSendVelocityAndAngular(Vector3 velocity, Vector3 angularVelocity)
if (syncVelocity)
{
this.velocity = velocity;
target.velocity = velocity;
}
this.angularVelocity = angularVelocity;
target.angularVelocity = angularVelocity;
}