Added proximity checking to NetworkedTransform
This commit is contained in:
parent
a44141a966
commit
ad88c20f86
@ -10,8 +10,8 @@ namespace MLAP
|
|||||||
{
|
{
|
||||||
public class NetworkedTransform : NetworkedBehaviour
|
public class NetworkedTransform : NetworkedBehaviour
|
||||||
{
|
{
|
||||||
[Range(0, 120)]
|
[Range(0f, 120f)]
|
||||||
public int SendsPerSecond = 20;
|
public float SendsPerSecond = 20;
|
||||||
[Tooltip("This assumes that the SendsPerSecond is synced across clients")]
|
[Tooltip("This assumes that the SendsPerSecond is synced across clients")]
|
||||||
public bool AssumeSyncedSends = true;
|
public bool AssumeSyncedSends = true;
|
||||||
[Tooltip("This requires AssumeSyncedSends to be true")]
|
[Tooltip("This requires AssumeSyncedSends to be true")]
|
||||||
@ -32,6 +32,10 @@ namespace MLAP
|
|||||||
private Vector3 lastSentPos;
|
private Vector3 lastSentPos;
|
||||||
private Quaternion lastSentRot;
|
private Quaternion lastSentRot;
|
||||||
|
|
||||||
|
public bool EnableProximity = false;
|
||||||
|
[Header("If enable proximity is turned on, on clients within this range will be recieving position updates from the server")]
|
||||||
|
public float ProximityRange = 50;
|
||||||
|
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
if (!AssumeSyncedSends && InterpolatePosition)
|
if (!AssumeSyncedSends && InterpolatePosition)
|
||||||
@ -161,10 +165,23 @@ namespace MLAP
|
|||||||
writer.Write(yRot);
|
writer.Write(yRot);
|
||||||
writer.Write(zRot);
|
writer.Write(zRot);
|
||||||
}
|
}
|
||||||
|
if(EnableProximity)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NetworkingManager.singleton.connectedClients.Count; i++)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(NetworkingManager.singleton.connectedClients[i].PlayerObject.transform.position, transform.position) <= ProximityRange)
|
||||||
|
{
|
||||||
|
SendToClientTarget(NetworkingManager.singleton.connectedClients[i].ClientId, "MLAPI_OnRecieveTransformFromServer", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_OnRecieveTransformFromServer", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
|
SendToNonLocalClientsTarget("MLAPI_OnRecieveTransformFromServer", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user