Exemple #1
0
    protected virtual void HandAttachedUpdate(Hand hand)
    {
        if (hand.IsGrabEnding(this.gameObject))
        {
            hand.DetachObject(gameObject);
            return;
        }

        Vector3 projection = Vector3.ProjectOnPlane(transformHelperHand.right, transformHelperParent.forward);
        Vector3 p1         = transformHelperParent.position;
        Vector3 p2         = transformHelperParent.position + projection;
        Vector2 xy         = transformHelperParent.InverseTransformPoint(p2);
        float   handAngle  = BraceletUtility.WrapTo360(Mathf.Atan2(xy.y, xy.x) * Mathf.Rad2Deg);

        if (Between(lastHandAngle, 0, 90) && (Between(handAngle, 270, 360)))
        {
            revolution--;
        }
        else if (Between(lastHandAngle, 270, 360) && (Between(handAngle, 0, 90)))
        {
            revolution++;
        }
        lastHandAngle = handAngle;
        float totalHandAngle = revolution * 360 + handAngle;

        angle = angleOnGrab + totalHandAngle / controlDisplay;
        angle = Mathf.Clamp(angle, angleMin - acumulatedAngle, angleMax - acumulatedAngle);

        if (discreteNotches)
        {
            if (notchReset)
            {
                transform.localEulerAngles = transform.localEulerAngles.WithZ(angle);
            }
        }
        else
        {
            transform.localEulerAngles = transform.localEulerAngles.WithZ(angle);
        }

        // check if inside notch
        int notch = InsideNotch();

        if (notch != -1)
        {
            currentNotch = notch;
            if (notchReset)
            {
                if (haptics)
                {
                    OnKnobNotch();
                }
                notchReset = false;
            }
        }
        else
        {
            TryNotchReset();
        }
    }
Exemple #2
0
    void UpdateAudio()
    {
        Vector3 direction = (listener.transform.position - audioSource.transform.position).normalized;

        audioAngle = Mathf.Abs(Vector3.Angle(audioSource.transform.forward, direction) - 90);

        float tAngle = Mathf.Clamp01(audioAngle / 90.0f);
        float tSpeed = BraceletUtility.Remap01Clamped(bladeSpeed, minSpeed, maxSpeed);

        audioSource.volume = angleVolumeCurve.Evaluate(tAngle) * speedVolumeCurve.Evaluate(tSpeed);;
        audioSource.pitch  = speedPitchCurve.Evaluate(tSpeed);;
    }
Exemple #3
0
 void UpdateAxes()
 {
     if (!lockYaw)
     {
         yawAngle = 30 * Mathf.Sin(Mathf.PI * 2 * yawFreq * yawTime);
         yawTime += Time.deltaTime;
     }
     bladeSpeed = BraceletUtility.Remap(speedKnob.KnobPercent(), 0, 1, minSpeed, maxSpeed);
     pitchAngle = BraceletUtility.Remap(pitchKnob.KnobPercent(), 0, 1, minAngle, maxAngle);
     pitchAxis.localEulerAngles  = new Vector3(-pitchAngle, 0, 0);
     yawAxis.localEulerAngles    = new Vector3(0, yawAngle, 0);
     bladeAxis.localEulerAngles += new Vector3(0, 0, bladeSpeed * speedGain) * Time.deltaTime;
 }
 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.layer == 13)
     {
         trail.enabled = true;
     }
     else
     {
         audioSource.PlayRandom(bounceSounds);
     }
     if (held)
     {
         var v = bracelet.GetVelocityEstimate().magnitude;
         var a = BraceletUtility.Remap(v, 0, 0.75f, 0.1f, 1);
         bracelet.tactors.VibrateAll(new Sine(175) * new ASR(0.0f, 0.1f, 0.15f, a));
     }
 }
Exemple #5
0
 public float KnobPercent()
 {
     return(BraceletUtility.Remap01Clamped(angle + acumulatedAngle, angleMin, angleMax));
 }