private void OnCollisionEnter(Collision collision)//Will be called before start
 {
     if (isActiveAndEnabled)
     {
         float speed = 1f;
         if (collision.contactCount > 0)
         {
             Vector3 point = collision.GetContact(0).point;
             Vector3 v1    = body.GetPointVelocity(point);
             Vector3 v2    = collision.rigidbody ? collision.rigidbody.GetPointVelocity(point) : Vector3.zero;
             speed = (v2 - v1).magnitude / hand.playerRoot.lossyScale.x;
         }
         float strength = Mathf.Lerp(0, hand.hapticSettings.collisionEnterMaxStrength, speed / hand.hapticSettings.collisionEnterMaxStrengthSpeed);
         hand.SendHapticImpulse(strength, hand.hapticSettings.collisionEnterDuration);
     }
 }
Example #2
0
    public void TransforAttached(XRHand other)
    {
        if (attached)
        {
            other.DetachIfAny();
            other.attached = attached;
            foreach (var c in attached.GetComponentsInChildren <Collider>())
            {
                other.IgnoreCollider(c);
            }
            attached = null;


            SendHapticImpulse(hapticSettings.detachStrength, hapticSettings.detachDuration);
            other.SendHapticImpulse(other.hapticSettings.attachStrength, other.hapticSettings.attachDuration);
        }
    }