// Collisions
        private void OnCollisionEnter(Collision collision)
        {
            // If we're using extrapolation, start simulating locally in order to make the bounce smoother.
            if (_extrapolation)
            {
                _stopExtrapolatingAtRoomTime = realtime.room.time;
            }

            // If we are currently the authoritative owner of this rigidbody and we've collided with a rigidbody that isn't owned by anyone, let's take over ownership and start simulating it.
            if (isOwnedLocally)
            {
                Rigidbody rigidbody = collision.rigidbody;
                if (rigidbody != null)
                {
                    RealtimeTransform otherRealtimeTransform = rigidbody.GetComponent <RealtimeTransform>();
                    if (otherRealtimeTransform != null)
                    {
                        // If the other realtime rigidbody isn't owned by anyone and it's not kinematic, take it over.
                        if (otherRealtimeTransform.isOwnedByWorld && !otherRealtimeTransform.model.isKinematic)
                        {
                            otherRealtimeTransform.RequestOwnership();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        void SetLocalPlayer(LocalPlayer localPlayer)
        {
            if (localPlayer == _localPlayer)
            {
                return;
            }

            _localPlayer = localPlayer;

            if (_localPlayer != null)
            {
                // TODO: Technically this shouldn't be needed. The RealtimeViewModel is created and locked to a user. The owner of that should progagate to children...
                RealtimeTransform rootRealtimeTransform = GetComponent <RealtimeTransform>();
                RealtimeTransform headRealtimeTransform = _head != null?_head.GetComponent <RealtimeTransform>() : null;

                RealtimeTransform leftHandRealtimeTransform = _leftHand != null?_leftHand.GetComponent <RealtimeTransform>() : null;

                RealtimeTransform rightHandRealtimeTransform = _rightHand != null?_rightHand.GetComponent <RealtimeTransform>() : null;

                if (rootRealtimeTransform != null)
                {
                    rootRealtimeTransform.RequestOwnership();
                }
                if (headRealtimeTransform != null)
                {
                    headRealtimeTransform.RequestOwnership();
                }
                if (leftHandRealtimeTransform != null)
                {
                    leftHandRealtimeTransform.RequestOwnership();
                }
                if (rightHandRealtimeTransform != null)
                {
                    rightHandRealtimeTransform.RequestOwnership();
                }
            }
        }