Exemple #1
0
 private void HandleGrabTriggered()
 {
     if (!grabManager.HasActiveGrabbable() && rangedGrabDetector.HasActiveRangedGrabTarget())
     {
         activeRangedGrabTarget = rangedGrabDetector.ActiveRangedGrabTarget;
     }
 }
Exemple #2
0
        private void HandleGripLetGo()
        {
            if (activeRangedGrabTarget != null)
            {
                activeRangedGrabTarget = null;

                if (executingRangedGrab)
                {
                    StopAllCoroutines();
                }
            }
        }
Exemple #3
0
        private IEnumerator ExecuteFlickRangedGrab()
        {
            var executionTime  = 0f;
            var originPosition = activeRangedGrabTarget.transform.parent.position;
            var originRotation = activeRangedGrabTarget.transform.parent.rotation;
            var distance       = (activeRangedGrabTarget.transform.position - transform.position).magnitude;
            var midPoint       = transform.position + transform.forward * distance * 1.25f;

            if (activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>())
            {
                activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().isKinematic = true;
                activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().useGravity  = false;
            }

            executingRangedGrab = true;

            while (executionTime < rangedGrabDuration)
            {
                if (activeRangedGrabTarget == null)
                {
                    break;
                }

                executionTime += Time.deltaTime;

                var percentT = executionTime / rangedGrabDuration;

                activeRangedGrabTarget.transform.parent.position = CalculateCurvedPoint(originPosition, midPoint, grabManager.transform.position, percentT);
                activeRangedGrabTarget.transform.parent.rotation = Quaternion.Slerp(originRotation, grabManager.transform.rotation, percentT * percentT);

                yield return(new WaitForEndOfFrame());
            }

            if (activeRangedGrabTarget != null)
            {
                if (activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>())
                {
                    activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().isKinematic = false;
                    activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().useGravity  = true;
                }

                grabManager.PerformGrab(activeRangedGrabTarget.Grabbable);
                activeRangedGrabTarget = null;
            }


            executingRangedGrab = false;
        }
Exemple #4
0
        private IEnumerator ExecuteRangedGrab()
        {
            var executionTime  = 0f;
            var originPosition = activeRangedGrabTarget.transform.parent.position;
            var originRotation = activeRangedGrabTarget.transform.parent.rotation;

            executingRangedGrab = true;

            if (activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>())
            {
                activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().isKinematic = true;
                activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().useGravity  = false;
            }

            while (executionTime < rangedGrabDuration)
            {
                if (activeRangedGrabTarget == null)
                {
                    break;
                }

                executionTime += Time.deltaTime;

                var percentT = executionTime / rangedGrabDuration;

                activeRangedGrabTarget.transform.parent.position = Vector3.Lerp(originPosition, grabManager.transform.position, percentT * percentT);
                activeRangedGrabTarget.transform.parent.rotation = Quaternion.Slerp(originRotation, grabManager.transform.rotation, percentT * percentT);

                yield return(new WaitForEndOfFrame());
            }

            if (activeRangedGrabTarget != null)
            {
                if (activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>())
                {
                    activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().isKinematic = false;
                    activeRangedGrabTarget.transform.parent.GetComponent <Rigidbody>().useGravity  = true;
                }

                grabManager.PerformGrab(activeRangedGrabTarget.Grabbable);
                activeRangedGrabTarget = null;
            }

            executingRangedGrab = false;
        }
        private void Update()
        {
            if (grabManager.HasActiveGrabbable())
            {
                return;
            }

            if (Physics.Raycast(new Ray(transform.position, transform.forward), out var hit, detectionRange, rangedGrabZoneLayer))
            {
                var rangedGrabTarget = hit.collider.GetComponent <RangedGrabTarget>();
                if (rangedGrabTarget != null && rangedGrabTarget != ActiveRangedGrabTarget)
                {
                    if (ActiveRangedGrabTarget != null)
                    {
                        ActiveRangedGrabTarget.Untarget();
                    }

                    ActiveRangedGrabTarget = rangedGrabTarget;

                    ActiveRangedGrabTarget.Target();
                }
            }