private void UpdatePinch() { bool pinchTriggered = false; bool releaseTriggered = false; float pinchStrength = 0; //Get grab position Vector3 thumbPos = leapManager.GetFingertipWorldPosition(0); Vector3 indexPos = leapManager.GetFingertipWorldPosition(1); grabPosition = thumbPos + (indexPos - thumbPos) / 2f; //Get pinch strength pinchStrength = leapManager.GetHandPinchStrength(); //if pinch strength is high enough if (pinchStrength >= pinchThreshold) { releaseCounter = 3; //Reset counter pinchTriggered = true; } else { if (releaseCounter > 0) { releaseCounter--; //Decrease counter } else { releaseTriggered = true; } } if (pinchTriggered && !pinching) { pinching = true; OnPinch(grabPosition); } if (releaseTriggered && pinching) { pinching = false; OnRelease(); } }
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); }