Exemplo n.º 1
0
        protected virtual void ThrowReleasedObject(Rigidbody objectRigidbody)
        {
            if (grabbedObjectScript != null)
            {
                VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(grabbedObjectScript.GetGrabbingObject());
                if (VRTK_ControllerReference.IsValid(controllerReference) && controllerReference.scriptAlias != null)
                {
                    VRTK_InteractGrab grabbingObjectScript = controllerReference.scriptAlias.GetComponent <VRTK_InteractGrab>();
                    if (grabbingObjectScript != null)
                    {
                        Transform origin = VRTK_DeviceFinder.GetControllerOrigin(controllerReference);

                        Vector3 velocity        = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
                        Vector3 angularVelocity = VRTK_DeviceFinder.GetControllerAngularVelocity(controllerReference);
                        float   grabbingObjectThrowMultiplier = grabbingObjectScript.throwMultiplier;

                        if (origin != null)
                        {
                            objectRigidbody.velocity        = origin.TransformVector(velocity) * (grabbingObjectThrowMultiplier * throwMultiplier);
                            objectRigidbody.angularVelocity = origin.TransformDirection(angularVelocity);

                            if (bow != null)
                            {
                                if (objectRigidbody.velocity.magnitude < 7.5f)
                                {
                                    bow.Thrown(false);
                                }
                                else
                                {
                                    bow.Thrown();
                                }

                                print(objectRigidbody.velocity.magnitude);
                            }
                            else
                            {
                                Debug.Log("NO BOW SCRIPT!");
                            }
                        }
                        else
                        {
                            objectRigidbody.velocity        = velocity * (grabbingObjectThrowMultiplier * throwMultiplier);
                            objectRigidbody.angularVelocity = angularVelocity;
                        }

                        if (throwVelocityWithAttachDistance)
                        {
                            Collider rigidbodyCollider = objectRigidbody.GetComponentInChildren <Collider>();
                            if (rigidbodyCollider != null)
                            {
                                Vector3 collisionCenter = rigidbodyCollider.bounds.center;
                                objectRigidbody.velocity = objectRigidbody.GetPointVelocity(collisionCenter + (collisionCenter - transform.position));
                            }
                            else
                            {
                                objectRigidbody.velocity = objectRigidbody.GetPointVelocity(objectRigidbody.position + (objectRigidbody.position - transform.position));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 void Update()
 {
     controllerVelocity = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
     angularVelocity    = VRTK_DeviceFinder.GetControllerAngularVelocity(controllerReference);
 }