예제 #1
0
        /// <summary>
        /// Modify each nearInteractable collision with hands attached grabbables.
        /// Only can be collision between attached grabbables and other interactables if HandVR of the attached (the hand) is NOT Blocked (HandVR is Blocked when it isn't visible) and near interactable is visible from the hand
        /// </summary>
        private void SetCollisionIgnores()
        {
            for (int i = 0; i < HandsVR.Length; i++)
            {
                if (HandsVR[i].AttachedGrabbable)
                {
                    int length = nearInteractables.Count;
                    for (int j = 0; j < length; j++)
                    {
                        //Following line seems unneeded. Ignore or not collisions with itself don't affect
                        //if (nearInteractables[j].gameObject == handsVR[i].AttachedGrabbable.gameObject) return;

                        //grabbable is blocked if grabbing hand is blocked or if grabbable is overlapping.
                        //if AttachedGrabbable is blocked or NOTHING -> following is deprecated ------->>>>>>   near interactable is NOT visible from hand, can't be collisions
                        //it's not worth to calculate VisibleFrom with every Collider of the nearInteractables
                        if (HandsVR[i].AttachedGrabbable.Blocked)                        // || !nearInteractables[j].transform.VisibleFrom(HandsVR[i].transform.position, DataVR.Instance.hand.blockingElements, QueryTriggerInteraction.Ignore))
                        {
                            PhysicsExt.IgnoreCollisions(nearInteractables[j].Colliders, HandsVR[i].AttachedGrabbable.Colliders, true);
                        }
                        else
                        {
                            PhysicsExt.IgnoreCollisions(nearInteractables[j].Colliders, HandsVR[i].AttachedGrabbable.Colliders, false);
                        }
                    }
                }
            }
        }
예제 #2
0
        public void Detach(bool fromAttachMethod = false)
        {
            //Debug.Log("Detach: " + this, gameObject);

            //TrackedPoseDriver approach
            {
                DestroyTrackedPoseDriver();
            }

            transform.DOKill();

            //SLOT
            //-------------------------------------------------
            if (!fromAttachMethod)
            {
                TryStore(OwnerHandVR);
            }
            //-------------------------------------------------

            OwnerHandVR.AttachedGrabbable = null;

            //not needed, the BelongState gives if it is attached, not need to check if ownerHandVR is null like before, so ownerHandVR mainstains the last ownerHandVR when state is changed until it is attached again
            //can be useful to return grabbable to last hand
            //OwnerHandVR = null;

            //if it has been attached to a slot
            if (Stored)
            {
                //Events
                OnDetached?.Invoke(OwnerHandVR);

#if UNITY_EDITOR
                Debug.Log("Dettached and Stored Grabbable: " + this + " from HandVR: " + OwnerHandVR, gameObject);
#endif

                return;
            }

            //TrackedPoseDriver approach
            {
                transform.position = /*OwnerHandVR.transform.position*/ OwnerHandVR.PoseProvider.AttachPosition;
                transform.rotation = /*OwnerHandVR.transform.rotation*/ OwnerHandVR.PoseProvider.AttachRotation;
            }

            transform.parent = null;

            AdjustPhysicsWithPhysicsTracker(OwnerHandVR);

            state = BelongState.Free;

            PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders, false);                //Undo Ignore Collisions between this and CharacterVR

            //Events
            OnDetached?.Invoke(OwnerHandVR);

#if UNITY_EDITOR
            Debug.Log("Dettached Grabbable: " + this + " from HandVR: " + OwnerHandVR, gameObject);
#endif
        }
예제 #3
0
        /// <summary>
        /// Removing near interactables.
        /// Important to make available collisions between them and attached grabbables again.
        /// </summary>
        /// <param name="interactable"></param>
        public void RemoveNearInteractables(Interactable interactable)
        {
            nearInteractables.Remove(interactable);

            //Reset collisions between attached interactables to hands and leaving interactable
            for (int i = 0; i < HandsVR.Length; i++)
            {
                if (HandsVR[i].AttachedGrabbable)
                {
                    PhysicsExt.IgnoreCollisions(interactable.Colliders, HandsVR[i].AttachedGrabbable.Colliders, false);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Make interactable be able to collide to nearInteractables.
        /// This is done to a interactable (grabbable) when it is detached.
        /// </summary>
        /// <param name="interactable"></param>
        public void FreeCollisionIgnores(Interactable interactable)
        {
            if (interactable == null)
            {
                return;
            }

            int length = nearInteractables.Count;

            for (int i = 0; i < length; i++)
            {
                PhysicsExt.IgnoreCollisions(nearInteractables[i].Colliders, interactable.Colliders, false);
            }
        }
예제 #5
0
        public void Attach(HandVR handVR, bool iterateAttachmentPoint = false)
        {
            //Debug.Log("Attach: " + this, gameObject);

            // TO DO: Test if not necessary I did it because maybe detach events are important. But attach should let things as they should be.
            if (Attached)
            {
                //True to avoid possible attach to Slot. Imagine you get from one hand to the other but the from hand is hovering a slot. then the detach will attach grabbable to the slot and then attach to the new hand making a strange effect
                Detach(true);
            }
            else if (Stored)
            {
                TryUnstore(OwnerSlot);
            }

            if (iterateAttachmentPoint)
            {
                currentAttachmentPointIndex++;
            }
            if (currentAttachmentPointIndex == attachmentPoints.Count)
            {
                currentAttachmentPointIndex = 0;
            }

            transform.DOKill();
            transform.parent         = handVR.transform;
            OwnerHandVR              = handVR; //Important to do this and next line before real physic attach (position and rotation) to be able to detach from it if other hand steal it on the fly to the hand
            handVR.AttachedGrabbable = this;
            DisableColliders();                //Disable collider to avoid not desired collisions on attach

            Vector3    attachPositionOffset = Vector3.zero;
            Quaternion attachRotationOffset = Quaternion.identity;

            GetLocalAttachmentPositionAndRotation(handVR.transform, out attachPositionOffset, out attachRotationOffset, handVR.AttachmentPointName.name, iterateAttachmentPoint);

            float attachTime = DataVR.Instance.grabbable.attachTime;

            transform.DOLocalMove(-attachPositionOffset, attachTime).SetEase(Ease.OutSine);
            transform.DOLocalRotate(-attachRotationOffset.eulerAngles, attachTime).SetEase(Ease.OutSine).OnComplete
            (
                () =>
            {
                PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders); //Ignore Collisions between this and CharacterVR
                EnableColliders();                                                                   //Enable collider (disabled above, before tween attach) WARNING. it is detected by ontriggerenter of physicsproximityAdjust

                //TrackedPoseDriver approach
                {
                    ////Set final position
                    ////-------------------------------------------------
                    //if (attachmentPoints.Count == 0 || (handVR.AttachmentPointName.name == "" && iterateAttachmentPoint == false))
                    //{
                    //	transform.localPosition = Vector3.zero;
                    //	transform.localRotation = Quaternion.identity;
                    //}
                    //else
                    //{
                    //	transform.localPosition = -attachPositionOffset;
                    //	transform.localRotation = Quaternion.Inverse(attachRotationOffset);
                    //}
                    ////-------------------------------------------------
                }

                //SLOT: as it could be in a slot make it kinematic again
                Rigidbody.interpolation          = RigidbodyInterpolation.None;
                Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                //TrackedPoseDriver approach
                {
                    //Original approach
                    //Rigidbody.isKinematic = true;

                    AddTrackedPoseDriver(handVR, attachPositionOffset, attachRotationOffset);
                }
                Rigidbody.useGravity = false;

                state = BelongState.Attached;

                //Events
                OnAttached?.Invoke(handVR);

#if UNITY_EDITOR
                Debug.Log("Attach Grabbable: " + this + " to HandVR: " + handVR, gameObject);
#endif
            }
            );
        }