Esempio n. 1
0
    private void UpdateActivity()
    {
        //Drop existing activity
        activity = Mathf.Min(1, activity - 0.05f);
        if (activity < 0.01f)
        {
            //And attacker
            activityAttacker = Mathf.Min(1, activityAttacker - 0.01f);
        }

        //For distance between palm and fingertips
        float fingerActivity = 0;

        for (int i = 0; i < fingerCount; i++)
        {
            fingerBendPrevious [i] = fingerBend [i];
            fingerBend [i]         = (leapManager.GetPalmPosition() - leapManager.GetFingertipPosition(i));

            fingerActivity += (fingerBend [i] - fingerBendPrevious [i]).magnitude;
        }

        //Filter out low activity
        fingerActivity = Mathf.Clamp(fingerActivity - 0.01f, 0, 5f);

        //For pinch strength (also to determine activity)
        float pinchActivity = 0;

        float grab = leapManager.GetHandPinchStrength();

        pinchActivity += Mathf.Abs(grabPrev - grab);
        grabPrev       = grab;

        //Filter out low activity
        fingerActivity = Mathf.Clamp(fingerActivity - 0.01f, 0, 10f);

        //Add all activity and subtract attacker
        activity = Mathf.Clamp(activity + pinchActivity / 5 + fingerActivity / 20 - activityAttacker, 0, 1f);

        //Update attacker
        activityAttacker = Mathf.Clamp(activityAttacker + activity / 20, 0, 5f);
    }