mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkRigidbody - syntax
This commit is contained in:
parent
0f013adc43
commit
faede54e14
@ -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,33 +118,25 @@ 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>
|
||||
/// Updates sync var values on server so that they sync to the client
|
||||
@ -231,10 +217,8 @@ void SendVelocity()
|
||||
|
||||
// only update syncTime if either has changed
|
||||
if (angularVelocityChanged || velocityChanged)
|
||||
{
|
||||
previousValue.nextSyncTime = now + syncInterval;
|
||||
}
|
||||
}
|
||||
|
||||
[Client]
|
||||
void SendRigidBodySettings()
|
||||
@ -289,10 +273,9 @@ void CmdSendVelocityAndAngular(Vector3 velocity, Vector3 angularVelocity)
|
||||
if (syncVelocity)
|
||||
{
|
||||
this.velocity = velocity;
|
||||
|
||||
target.velocity = velocity;
|
||||
|
||||
}
|
||||
|
||||
this.angularVelocity = angularVelocity;
|
||||
target.angularVelocity = angularVelocity;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user