diff --git a/Editor/HumanoidControl/HumanoidControl_Editor.cs b/Editor/HumanoidControl/HumanoidControl_Editor.cs index 2e3c59a..d969e7e 100644 --- a/Editor/HumanoidControl/HumanoidControl_Editor.cs +++ b/Editor/HumanoidControl/HumanoidControl_Editor.cs @@ -712,6 +712,7 @@ namespace Passer { CalibrateAtStartSetting(); StartPositionSetting(); ScalingSetting(); + FloatCorrectionSetting(); DontDestroySetting(); if (IsPrefab(humanoid)) DisconnectInstancesSetting(); @@ -770,6 +771,15 @@ namespace Passer { scalingProp.intValue = (int)(HumanoidControl.ScalingType)EditorGUILayout.EnumPopup(text, (HumanoidControl.ScalingType)scalingProp.intValue); } + protected void FloatCorrectionSetting() { + SerializedProperty floatCorrectionProp = serializedObject.FindProperty(nameof(HumanoidControl.floatCorrection)); + GUIContent text = new GUIContent( + "Float Correction", + "Correct floating avatars when user is taller than the avatar" + ); + floatCorrectionProp.boolValue = EditorGUILayout.Toggle(text, floatCorrectionProp.boolValue); + } + private void ShowTrackers(HumanoidControl humanoid, bool shown) { foreach (Tracker tracker in humanoid.trackers) tracker.ShowTracker(shown); diff --git a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs index 96ec403..afe7028 100644 --- a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs +++ b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs @@ -2112,6 +2112,12 @@ namespace Passer.Humanoid { // So probably this setting should only be used when using animations. public bool useLegLengthCorrection = false; private float legLengthCorrection = 0; + + /// + /// Correct floating avatars when user is taller than the avatar + /// + public bool floatCorrection = false; + protected void CheckGrounded() { Vector3 footBase = GetHumanoidPosition(); //footBase += legLengthBias * Vector3.up; @@ -2146,6 +2152,13 @@ namespace Passer.Humanoid { legLengthCorrection = 0.99F * legLengthCorrection + 0.01F * footBoneDistance.y; } + + if (floatCorrection) { + float leftFootBoneDistance = leftFootTarget.foot.bone.transform.position.y - leftFootTarget.foot.target.transform.position.y; + float rightFootBoneDistance = rightFootTarget.foot.bone.transform.position.y - rightFootTarget.foot.target.transform.position.y; + if (leftFootBoneDistance > 0.02F && rightFootBoneDistance > 0.02F) + AdjustTrackingHeight(-0.01F); + } } public float GetDistanceToGroundAt(Vector3 position, float maxDistance) {