public override sealed void UpdateExtension(TargetConstraint t) { // Linear limit t.joint.xMotion = ConfigurableJointMotion.Locked; t.joint.yMotion = ConfigurableJointMotion.Locked; t.joint.zMotion = ConfigurableJointMotion.Limited; limitSpring.spring = spring; limitSpring.damper = damper; t.joint.linearLimitSpring = limitSpring; worldLimitStart = t.connectedAnchor.position - t.GetJointAxisWorldRotation() * Vector3.forward * limit.limit; worldLimitEnd = t.connectedAnchor.position + t.GetJointAxisWorldRotation() * Vector3.forward * limit.limit; if (showLimitedAxis) { Debug.DrawLine(worldLimitStart, worldLimitEnd, Color.black); } // Threshold detection if (detectThreshold) { if (togglingThresholdDetectionIn <= 0.0f) { closestToLine = BasicHelpers.NearestPointOnFiniteLine(worldLimitStart, worldLimitEnd, t.anchor.position); if (inverted) { positionLerp = Vector3.Distance(worldLimitStart, closestToLine) / (limit.limit * 2.0f); } else { positionLerp = Vector3.Distance(worldLimitEnd, closestToLine) / (limit.limit * 2.0f); } if (positionLerp > threshold && thresholdState != ThresholdState.Over) { togglingThresholdDetectionIn = minTimeBetweenDetections; thresholdState = ThresholdState.Over; onOverThreshold.Invoke(); } else if (positionLerp < threshold && thresholdState != ThresholdState.Under) { togglingThresholdDetectionIn = minTimeBetweenDetections; thresholdState = ThresholdState.Under; onUnderThreshold.Invoke(); } } else { togglingThresholdDetectionIn -= Time.deltaTime; } } }
public override sealed void FingerLerpUpdate() { base.FingerLerpUpdate(); // Lerp minDist = conf.minPalmRelDistance * hand.totalScale; maxDist = conf.maxPalmRelDistance * hand.totalScale; nearestPointToLine = BasicHelpers.NearestPointOnFiniteLine(hand.palmExterior.transformRef.position, hand.palmInterior.transformRef.position, finger.tip.transformRef.position); dist = Vector3.Distance(nearestPointToLine, finger.tip.transformRef.position); _lerp = 1.0f - Mathf.InverseLerp(minDist, maxDist, dist); // Intention _providesIntention = false; }