예제 #1
0
        void Start()
        {
            LeftGrabber = GameObject.Find("LeftController").GetComponentInChildren <Grabber>();
            gitLeft     = LeftGrabber.GetComponent <GrabbablesInTrigger>();

            RightGrabber = GameObject.Find("RightController").GetComponentInChildren <Grabber>();
            gitRight     = RightGrabber.GetComponent <GrabbablesInTrigger>();

            requestedGrabbables = new Dictionary <int, double>();
        }
예제 #2
0
        void setupConfigJoint(Grabber g)
        {
            connectedJoint = g.GetComponent <ConfigurableJoint>();
            connectedJoint.autoConfigureConnectedAnchor = false;
            connectedJoint.connectedBody = rigid;

            float anchorOffsetVal = (1 / g.transform.localScale.x) * -1;

            connectedJoint.anchor = Vector3.zero;

            connectedJoint.connectedAnchor = GrabPositionOffset;
        }
예제 #3
0
        public virtual void DropItem(Grabber droppedBy, bool resetVelocity, bool resetParent)
        {
            // Nothing holding us
            if (heldByGrabbers == null)
            {
                BeingHeld = false;
                return;
            }

            if (resetParent)
            {
                ResetParent();
            }

            //disconnect all joints and set the connected object to null
            removeConfigJoint();

            //  If something called drop on this item we want to make sure the parent knows about it
            // Reset's Grabber position, grabbable state, etc.
            if (droppedBy)
            {
                droppedBy.DidDrop();
            }

            // Release item and apply physics force to it
            if (rigid != null)
            {
                rigid.isKinematic            = wasKinematic;
                rigid.useGravity             = usedGravity;
                rigid.interpolation          = initialInterpolationMode;
                rigid.collisionDetectionMode = initialCollisionMode;
            }

            if (events != null)
            {
                for (int x = 0; x < events.Count; x++)
                {
                    events[x].OnRelease();
                }
            }

            // No longer have a primary Grab Offset set
            primaryGrabOffset = null;

            // No longer looking at a 2h object
            clearLookAtTransform();

            removeGrabber(droppedBy);

            BeingHeld      = false;
            didParentHands = false;
            LastDropTime   = Time.time;

            // Apply velocity last
            if (rigid && resetVelocity && droppedBy && AddControllerVelocityOnDrop)
            {
                // Make sure velocity is passed on
                Vector3 velocity        = droppedBy.GetGrabberAveragedVelocity() + droppedBy.GetComponent <Rigidbody>().velocity;
                Vector3 angularVelocity = droppedBy.GetGrabberAveragedAngularVelocity() + droppedBy.GetComponent <Rigidbody>().angularVelocity;

                // Oculus Quest Angular Velocity is backwards
                if (input.IsOculusQuest())
                {
                    angularVelocity = -angularVelocity;
                }

                if (gameObject.activeSelf)
                {
                    StartCoroutine(Release(velocity, angularVelocity));
                }
            }
        }
예제 #4
0
        public virtual void GrabItem(Grabber grabbedBy)
        {
            // Make sure we release this item
            if (BeingHeld && SecondaryGrabBehavior != OtherGrabBehavior.DualGrab)
            {
                DropItem(false, true);
            }

            // Make sure all values are reset first
            ResetGrabbing();

            // Officially being held
            BeingHeld    = true;
            LastGrabTime = Time.time;

            // Set where the item will move to on the grabber
            primaryGrabOffset = GetClosestGrabPoint(grabbedBy);

            // Update held by properties
            addGrabber(grabbedBy);
            grabTransform.parent = grabbedBy.transform;

            grabbedBy.transform.localEulerAngles = GrabRotationOffset;

            // Hide the hand graphics if necessary
            if (HideHandGraphics)
            {
                grabbedBy.HideHandGraphics();
            }

            // Use center of grabber if snapping
            if (GrabMechanic == GrabType.Snap)
            {
                grabTransform.localEulerAngles = Vector3.zero;
                grabTransform.localPosition    = GrabPositionOffset;
            }
            // Precision hold can use position of what we're grabbing
            else if (GrabMechanic == GrabType.Precise)
            {
                grabTransform.position = transform.position;
                grabTransform.rotation = transform.rotation;
            }

            // First remove any connected joints if necessary
            var projectile = GetComponent <Projectile>();

            if (projectile)
            {
                var fj = GetComponent <FixedJoint>();
                if (fj)
                {
                    Destroy(fj);
                }
            }

            // Set up the new connected joint
            if (GrabPhysics == GrabPhysics.PhysicsJoint && GrabMechanic == GrabType.Precise)
            {
                connectedJoint = grabbedBy.GetComponent <ConfigurableJoint>();
                connectedJoint.connectedBody = rigid;
                // Just let the autoconfigure handle the calculations for us
                connectedJoint.autoConfigureConnectedAnchor = true;
            }

            // Set up the connected joint for snapping
            if (GrabPhysics == GrabPhysics.PhysicsJoint && GrabMechanic == GrabType.Snap)
            {
                // Need to Fix Rotation on Snap Physics when close by
                transform.rotation = grabTransform.rotation;


                // Setup joint
                setupConfigJoint(grabbedBy);
            }

            if (GrabPhysics == GrabPhysics.Kinematic)
            {
                if (ParentToHands)
                {
                    transform.parent = grabbedBy.transform;
                }

                if (rigid != null)
                {
                    rigid.isKinematic = true;
                }
            }

            // Let events know we were grabbed
            for (int x = 0; x < events.Count; x++)
            {
                events[x].OnGrab(grabbedBy);
            }

            journeyLength = Vector3.Distance(grabPosition, grabbedBy.transform.position);
        }