set kinematic

This commit is contained in:
vis2k 2021-09-05 20:15:37 +08:00 committed by mischa
parent 2dd36a4d01
commit cc5db0a98c

View File

@ -5,5 +5,33 @@ namespace Mirror
[RequireComponent(typeof(Rigidbody))]
public class NetworkRigidbody : NetworkTransform
{
// cache the Rigidbody component
Rigidbody rb;
void Awake() { rb = GetComponent<Rigidbody>(); }
// FixedUpdate for physics
void FixedUpdate()
{
// who ever has authority moves the Rigidbody with physics.
// everyone else simply sets it to kinematic.
// so that only the Transform component is synced.
if (isClient)
{
// on the client, force kinematic if server has authority.
// or if another client (not us) has authority.
// otherwise don't touch isKinematic.
// the authority owner might use it either way.
if (!IsClientWithAuthority)
rb.isKinematic = true;
}
else if (isServer)
{
// on the server, force kinematic if a client has authority.
// otherwise don't touch isKinematic.
// the authority owner might use it either way.
if (clientAuthority)
rb.isKinematic = true;
}
}
}
}