Example #1
0
    protected virtual void OnCollisionEnter(Collision collision)
    {
        // This means that the weapon is thrown and hit a surface
        if (inFlight)
        {
            OnHitSurface(collision.transform);
            CheckIfEnemyAndDealDamage(collision, collision.contacts[0].point, velocity);
            inFlight = false;
        }


        if (twoHanded)
        {
            velocity *= 3;
        }

        if (VRTK_ControllerReference.IsValid(controllerReference) && IsGrabbed() && velocity > 8)
        {
            collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
            var hapticStrength = collisionForce / maxCollisionForce;
            VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f);
            CheckIfEnemyAndDealDamage(collision, collision.contacts[0].point, velocity);

            AudioManager.instance.PlayClip(AudioManager.SoundFX.Impact, transform.position);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (controllerReference == null)
        {
            return;
        }

        if (rigidbody_held == true)
        {
            Vector3 velocity = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
            controller_speed = velocity.magnitude;
            if (controller_speed >= 1)
            {
                float scale_factor = controller_speed / max_controller_speed;
                haptic_strength = Mathf.Lerp(0, 1, scale_factor);
                VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, haptic_strength, haptic_duration, haptic_delay);
            }
        }
        else
        {
            if (rb.velocity.magnitude >= 1)
            {
                float scale_factor = rb.velocity.magnitude / max_rb_speed;
                haptic_strength = Mathf.Lerp(0, 1, scale_factor);
                VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, haptic_strength, haptic_duration, haptic_delay);
            }
        }
    }
Example #3
0
        /// <summary>
        /// The difference in velocity of the two controllers.
        /// </summary>
        /// <returns>A 3-dimensional vector, equal to the difference between the controller's [0] velocities in the x direction, [1] velocities in the y direction (float), and [2] velocities in the z direction (float).</returns>
        public Vector3 VelocityDelta()
        {
            Vector3 LeftVelocity  = VRTK_DeviceFinder.GetControllerVelocity(VRTK_DeviceFinder.GetControllerReferenceLeftHand());
            Vector3 RightVelocity = VRTK_DeviceFinder.GetControllerVelocity(VRTK_DeviceFinder.GetControllerReferenceRightHand());

            return(LeftVelocity - RightVelocity);
        }
Example #4
0
        private IEnumerator SearchForHandControllerCoroutine()
        {
            WaitForSeconds wait = new WaitForSeconds(0.1f);

            while (!IsBeaten)
            {
                Collider[] colliderArr = Physics.OverlapSphere(transform.position, beatRange, 1 << LayerMask.NameToLayer("PLayerController"));
                // print(colliderArr.Length);
                foreach (Collider coll in colliderArr)
                {
                    VRTK_ControllerEvents controllerEvents = coll.GetComponent <VRTK_ControllerEvents>();

                    if (controllerEvents != null)
                    {
                        VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(controllerEvents.gameObject);

                        var controllerVelocity = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
                        // print(controllerVelocity);
                        //print(controllerVelocity.magnitude);
                        if (controllerVelocity.magnitude > beatVelocity)
                        {
                            OnBeaten(this, new BeatableObjectArgs());
                            break;
                        }
                    }
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        OnBeaten(this, new BeatableObjectArgs());
                        break;
                    }
                }
                yield return(wait);
            }
        }
Example #5
0
    void Update()
    {
        if (checkingForRelease)
        {
            currentReleaseDifference += Time.deltaTime;

            if (currentReleaseDifference > releaseTolerance)
            {
                checkingForRelease = false;
                canShoot           = false;

                currentReleaseDifference = 0;

                Destroy(currentOrb);
                currentOrb = null;
            }
            else if (!rightHand.triggerPressed && !leftHand.triggerPressed)
            {
                canShoot           = true;
                checkingForRelease = false;
            }
        }
        else if (canShoot)
        {
            // Try to shoot
            Vector3 leftHandVelocity  = VRTK_DeviceFinder.GetControllerVelocity(VRTK_ControllerReference.GetControllerReference(leftHand.gameObject));
            Vector3 rightHandVelocity = VRTK_DeviceFinder.GetControllerVelocity(VRTK_ControllerReference.GetControllerReference(rightHand.gameObject));

            Vector3 averageVelocity = (leftHandVelocity + rightHandVelocity) / 2;

            if (Vector3.Angle(rightHandVelocity, leftHandVelocity) < 90 && averageVelocity.magnitude >= shootTolerance)
            {
                currentOrb.GetComponent <Rigidbody>().isKinematic = false;
                currentOrb.GetComponent <Rigidbody>().velocity    = averageVelocity * shootMultiplier;
                Destroy(currentOrb, 5);
            }
            else
            {
                Destroy(currentOrb);
            }

            currentOrb = null;
            canShoot   = false;
        }
        else if (!leftHandTouch.GetTouchedObject() && !rightHandTouch.GetTouchedObject())
        {
            if (leftHand.triggerPressed && rightHand.triggerPressed)
            {
                if (!currentOrb)
                {
                    currentOrb = Instantiate(magicOrbPrefab, Vector3.Lerp(leftHand.transform.position, rightHand.transform.position, 0.5f), Quaternion.identity);
                }
                else
                {
                    currentOrb.transform.position = Vector3.Lerp(leftHand.transform.position, rightHand.transform.position, 0.5f);
                }
            }
        }
    }
Example #6
0
 private void Io_InteractableObjectUngrabbed(object sender, InteractableObjectEventArgs e)
 {
     CancelInvoke("DoHaptics");
     if (controllerReference != null)
     {
         Debug.Log(VRTK_DeviceFinder.GetControllerVelocity(controllerReference));
         VRTK_ControllerHaptics.CancelHapticPulse(controllerReference);
     }
     controllerReference = null;
 }
Example #7
0
    protected override 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 (enemy != null && enemy.hitPoints > 0)
                        {
                            //enemy.OnOffCollider (true,false);
                            isThrow           = true;
                            rbGrab            = this.GetComponent <Rigidbody> ();
                            rbGrab.useGravity = true;
                        }
                        else
                        {
                        }
                    }
                    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));
                        }
                    }
                }
            }
        }
    }
        public override void Ungrabbed(GameObject previousGrabbingObject)
        {
            VRTK_ControllerEvents events = previousGrabbingObject.GetComponent <VRTK_ControllerEvents>();

            var velocity        = VRTK_DeviceFinder.GetControllerVelocity(previousGrabbingObject);
            var angularVelocity = VRTK_DeviceFinder.GetControllerAngularVelocity(previousGrabbingObject);

            MyRB.AddForce(angularVelocity * angularVelocityMultiplier);

            base.Ungrabbed(previousGrabbingObject);
        }
Example #9
0
 protected override void Update()
 {
     base.Update();
     controllerSpeed = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
     if (controllerSpeed > 30)
     {
         rigi.useGravity  = true;
         rigi.isKinematic = false;
         Destroy(gameObject, 2);
     }
 }
Example #10
0
 public Vector3 GetVelocity()
 {
     if (VRTK_ControllerReference.IsValid(controllerReference) && IsGrabbed())
     {
         return(VRTK_DeviceFinder.GetControllerVelocity(controllerReference));
     }
     else
     {
         return(Vector3.zero);
     }
 }
Example #11
0
 // Token: 0x06001E0C RID: 7692 RVA: 0x000989A4 File Offset: 0x00096BA4
 private void OnCollisionEnter(Collision collision)
 {
     if (VRTK_ControllerReference.IsValid(this.controllerReference) && this.IsGrabbed(null))
     {
         this.collisionForce = VRTK_DeviceFinder.GetControllerVelocity(this.controllerReference).magnitude *this.impactMagnifier;
         float strength = this.collisionForce / this.maxCollisionForce;
         VRTK_ControllerHaptics.TriggerHapticPulse(this.controllerReference, strength, 0.5f, 0.01f);
         return;
     }
     this.collisionForce = collision.relativeVelocity.magnitude * this.impactMagnifier;
 }
Example #12
0
    protected override 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 (weapon != null)
                        {
                            weapon.Thrown();
                        }
                        else
                        {
                            Debug.Log("NO SPEAR 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));
                        }
                    }
                }
            }
        }
    }
Example #13
0
        /// <summary>
        /// The dot product of the difference in velocity between the two controllers and their local distance. Can be used as a local scaling factor.
        /// </summary>
        /// <returns>A float that approximates a reasonable (neither too fast, nor too slow) local scaling factor.</returns>
        public float LocalScalingFactor()
        {
            Vector3 LeftVelocity  = VRTK_DeviceFinder.GetControllerVelocity(VRTK_DeviceFinder.GetControllerReferenceLeftHand());
            Vector3 RightVelocity = VRTK_DeviceFinder.GetControllerVelocity(VRTK_DeviceFinder.GetControllerReferenceRightHand());
            Vector3 VelocityDelta = LeftVelocity - RightVelocity;

            Vector3 LeftLocalPosition  = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.LeftController).localPosition;
            Vector3 RightLocalPosition = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.RightController).localPosition;
            Vector3 localDistance      = LeftLocalPosition - RightLocalPosition;

            return(Vector3.Dot(VelocityDelta, localDistance));
        }
        void MakeItSo()
        {
            if (controllerReference == null)
            {
                Debug.Log("You need an ID or Gameobject of the controller");
                return;
            }

            controllerVelocity.Value = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
            VelocityNormalized.Value = controllerVelocity.Value.normalized;
            Magnitiude.Value         = controllerVelocity.Value.magnitude;
        }
Example #15
0
 private void OnTriggerEnter(Collider collision)
 {
     if (collision.tag != "Player")
     {
         if (controllerActions && IsGrabbed())
         {
             OverlapForce = VRTK_DeviceFinder.GetControllerVelocity(controllerActions.gameObject).magnitude *impactMagnifier;
             var hapticStrength = OverlapForce / maxCollisionForce;
             controllerActions.TriggerHapticPulse(hapticStrength, 0.5f, 0.01f);
         }
     }
 }
Example #16
0
 private void OnCollisionEnter(Collision collision)
 {
     if (grabbingController != null && IsGrabbed())
     {
         collisionForce = VRTK_DeviceFinder.GetControllerVelocity(grabbingController).magnitude *impactMagnifier;
         var hapticStrength = collisionForce / maxCollisionForce;
         VRTK_SharedMethods.TriggerHapticPulse(VRTK_DeviceFinder.GetControllerIndex(grabbingController), hapticStrength, 0.5f, 0.01f);
     }
     else
     {
         collisionForce = collision.relativeVelocity.magnitude * impactMagnifier;
     }
 }
Example #17
0
 private void OnCollisionEnter(Collision collision)
 {
     if (VRTK_ControllerReference.IsValid(controllerReference) && IsGrabbed())
     {
         collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
         var hapticStrength = collisionForce / maxCollisionForce;
         VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f);
     }
     else
     {
         collisionForce = collision.relativeVelocity.magnitude * impactMagnifier;
     }
 }
Example #18
0
    private List <float> ControllerVelocityAndAmplitude()
    {
        List <float> controllerData = new List <float>();
        float        velocity       = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude;
        float        height         = controllerDevice.transform.position.y;

        height   = ModelUtility.Remap(height, 0, 4, 0, 20000);
        velocity = ModelUtility.Remap(velocity, 0, 5, 0, 1);

        controllerData.Add(height);   //Send OSC Amplitude based on velocity. hover at .3
        controllerData.Add(velocity); //Send OSC Frequency based on y
        return(controllerData);
    }
Example #19
0
 private void OnCollisionEnter(Collision collision)
 {
     if (controllerActions && IsGrabbed())
     {
         collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerActions.gameObject).magnitude *impactMagnifier;
         var hapticStrength = collisionForce / maxCollisionForce;
         controllerActions.TriggerHapticPulse(hapticStrength, 0.5f, 0.01f);
     }
     else
     {
         collisionForce = collision.relativeVelocity.magnitude * impactMagnifier;
     }
 }
Example #20
0
 private void OnCollisionEnter(Collision collision)
 {
     Debug.Log("Hammer Collided with something=" + collision.collider.name);
     if (VRTK_ControllerReference.IsValid(controllerReference) && IsGrabbed())
     {
         collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
         var hapticStrength = collisionForce / maxCollisionForce;
         VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.4f, 0.01f);
         AudioSource audio = GetComponent <AudioSource> ();
         audio.Play();
     }
     else
     {
         collisionForce = collision.relativeVelocity.magnitude * impactMagnifier;
     }
 }
Example #21
0
 private void Pulse()
 {
     if (VRTK_ControllerReference.IsValid(controllerReference))
     {
         collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
         var hapticStrength = collisionForce / maxCollisionForce;
         VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f);
     }
     else
     {
         var controllerEvent = GetComponentInChildren <VRTK_ControllerEvents>();
         if (controllerEvent != null && controllerEvent.gameObject != null)
         {
             controllerReference = VRTK_ControllerReference.GetControllerReference(controllerEvent.gameObject);
         }
     }
 }
Example #22
0
        private void ThrowReleasedObject(Rigidbody objectRigidbody)
        {
            if (grabbedObjectScript)
            {
                var grabbingObject = grabbedObjectScript.GetGrabbingObject();
                if (grabbingObject)
                {
                    var grabbingObjectScript = grabbingObject.GetComponent <VRTK_InteractGrab>();

                    var grabbingObjectThrowMultiplier = grabbingObjectScript.throwMultiplier;

                    var origin = VRTK_DeviceFinder.GetControllerOrigin(grabbingObject);

                    var velocity        = VRTK_DeviceFinder.GetControllerVelocity(grabbingObject);
                    var angularVelocity = VRTK_DeviceFinder.GetControllerAngularVelocity(grabbingObject);

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

                    if (throwVelocityWithAttachDistance)
                    {
                        var rigidbodyCollider = objectRigidbody.GetComponentInChildren <Collider>();
                        if (rigidbodyCollider)
                        {
                            Vector3 collisionCenter = rigidbodyCollider.bounds.center;
                            objectRigidbody.velocity = objectRigidbody.GetPointVelocity(collisionCenter + (collisionCenter - transform.position));
                        }
                        else
                        {
                            objectRigidbody.velocity = objectRigidbody.GetPointVelocity(objectRigidbody.position + (objectRigidbody.position - transform.position));
                        }
                    }
                }
            }
        }
Example #23
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log(" FORCE start   " + collisionForce);


        if (other.tag == "Ariana")
        {
            if (controllerActions && IsGrabbed())
            {
                collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerActions.gameObject).magnitude *impactMagnifier;


                if (collisionForce > 235 && !end)
                {
                    end = true;
                    StartCoroutine(endgame());
                }
            }
        }
    }
Example #24
0
    private void OnCollisionEnter(Collision collision)
    {
        VRTK_ControllerEvents events = collision.gameObject.GetComponent <VRTK_ControllerEvents>();

        controllerReference = VRTK_ControllerReference.GetControllerReference(events.gameObject);

        collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
        var hapticStrength = collisionForce / maxCollisionForce;

        VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.1f, 0.05f);
        float collisionMidi = ModelUtility.Remap(collisionForce, 0, 100, 70, 127);

        List <float> pianoData = new List <float>();

        pianoData.Add(midiNote);
        pianoData.Add(collisionMidi);

        OSCHandler.Instance.SendMessageToClient("myClient", "/pianoKey/" + keyNumber, pianoData);
        textComponent.text = "/pianoKey/" + keyNumber + ", " + midiNote + " , " + collisionMidi;
    }
Example #25
0
    private void FixedUpdate()
    {
        try
        {
            if (device != null)
            {
                this.velocity  = VRTK_DeviceFinder.GetControllerVelocity(device);
                this.direction = device.actual.transform.position - lastPos;
                this.lastPos   = device.actual.transform.position;
            }
        } catch
        {
            //
        }


        if (controllerEventHandler.controllerVisible && device == null)
        {
            getControllerReference();
        }
    }
    void OnCollisionEnter(Collision col)
    {
        if (initialized)
        {
            if ((rb.velocity.magnitude >= 1.8f) || (col.gameObject.layer == (int)ObjectLayer.Room && rb.velocity.magnitude >= 1.0f))
            {
                Break();
            }

            controllerReference = VRTK_ControllerReference.GetControllerReference(gameObject.GetComponent <VRTK_InteractableObject>().GetGrabbingObject());
            if (VRTK_ControllerReference.IsValid(controllerReference) && gameObject.GetComponent <VRTK_InteractableObject>().IsGrabbed())
            {
                collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude;
                if (collisionForce >= 2.0f)
                {
                    float hapticStrength = collisionForce / maxCollisionForce;
                    VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f);
                    Break();
                }
            }
        }
    }
Example #27
0
 // Token: 0x06001D4E RID: 7502 RVA: 0x00095E6C File Offset: 0x0009406C
 protected virtual void ThrowReleasedObject(Rigidbody objectRigidbody)
 {
     if (this.grabbedObjectScript != null)
     {
         VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(this.grabbedObjectScript.GetGrabbingObject());
         if (VRTK_ControllerReference.IsValid(controllerReference) && controllerReference.scriptAlias != null)
         {
             VRTK_InteractGrab component = controllerReference.scriptAlias.GetComponent <VRTK_InteractGrab>();
             if (component != null)
             {
                 Transform controllerOrigin          = VRTK_DeviceFinder.GetControllerOrigin(controllerReference);
                 Vector3   controllerVelocity        = VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
                 Vector3   controllerAngularVelocity = VRTK_DeviceFinder.GetControllerAngularVelocity(controllerReference);
                 float     num = component.throwMultiplier;
                 if (controllerOrigin != null)
                 {
                     objectRigidbody.velocity        = controllerOrigin.TransformVector(controllerVelocity) * (num * this.throwMultiplier);
                     objectRigidbody.angularVelocity = controllerOrigin.TransformDirection(controllerAngularVelocity);
                 }
                 else
                 {
                     objectRigidbody.velocity        = controllerVelocity * (num * this.throwMultiplier);
                     objectRigidbody.angularVelocity = controllerAngularVelocity;
                 }
                 if (this.throwVelocityWithAttachDistance)
                 {
                     Collider componentInChildren = objectRigidbody.GetComponentInChildren <Collider>();
                     if (componentInChildren != null)
                     {
                         Vector3 center = componentInChildren.bounds.center;
                         objectRigidbody.velocity = objectRigidbody.GetPointVelocity(center + (center - base.transform.position));
                         return;
                     }
                     objectRigidbody.velocity = objectRigidbody.GetPointVelocity(objectRigidbody.position + (objectRigidbody.position - base.transform.position));
                 }
             }
         }
     }
 }
Example #28
0
    void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 1f, layer))
        {
            float hapticStrength = 0f;

            if (VRTK_ControllerReference.IsValid(controllerReference))
            {
                collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
                hapticStrength = collisionForce / maxCollisionForce;
            }

            if (hapticStrength > 0.05f)
            {
                if (!string.IsNullOrWhiteSpace(hit.transform.tag) && hit.transform.CompareTag("CubeNonDirection"))
                {
                    if (Vector3.Angle(transform.position - previousPos, hit.transform.up) > 130 ||
                        Vector3.Angle(transform.position - previousPos, hit.transform.right) > 130 ||
                        Vector3.Angle(transform.position - previousPos, -hit.transform.up) > 130 ||
                        Vector3.Angle(transform.position - previousPos, -hit.transform.right) > 130)
                    {
                        SliceObject(hit.transform);
                    }
                }
                else
                {
                    if (Vector3.Angle(transform.position - previousPos, hit.transform.up) > 130)
                    {
                        SliceObject(hit.transform);
                    }
                }
            }
        }

        previousPos = transform.position;
    }
Example #29
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag != "Pad" && collision.gameObject.GetComponent <VRTK_ControllerEvents>() != null)
        {
            VRTK_ControllerEvents events = collision.gameObject.GetComponent <VRTK_ControllerEvents>();
            controllerReference = VRTK_ControllerReference.GetControllerReference(events.gameObject);

            collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
            var hapticStrength = collisionForce / maxCollisionForce;
            VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.1f, 0.05f);
            float collisionMidi = ModelUtility.Remap(collisionForce, 0, 100, 70, 127);

            List <float> padData = new List <float>();
            padData.Add(padY);
            padData.Add(padX);
            padData.Add(midiNote);
            padData.Add(collisionMidi);

            OSCHandler.Instance.SendMessageToClient("myClient", "/drumPad", padData);
            textComponent.text = "/drumPad: " + padData[0] + ", " + padData[1] + ", " + midiNote + " , " + collisionMidi;
        }
        StartCoroutine(Reposition());
    }
Example #30
0
    private float Pulse()
    {
        var hapticStrength = 0f;

        if (VRTK_ControllerReference.IsValid(controllerReference))
        {
            collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude *impactMagnifier;
            hapticStrength = collisionForce / maxCollisionForce;

#if UNITY_ANDROID
            var controller = controllerReference.actual.GetComponent <QuestHapticFeedback>();
            StartCoroutine(controller.HapticPulse(0.5f, 0.01f, 0.5f, hapticStrength, false));
#else
            VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f);
#endif
        }
        else
        {
            UpdateControllerReference();
        }

        return(hapticStrength);
    }