mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
set kinematic
This commit is contained in:
parent
2dd36a4d01
commit
cc5db0a98c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user