Added floating avatar correction

This commit is contained in:
Pascal Serrarens 2022-07-28 13:52:31 +02:00
parent a055ff337a
commit 69a1ed2fff
2 changed files with 23 additions and 0 deletions

View File

@ -712,6 +712,7 @@ namespace Passer {
CalibrateAtStartSetting(); CalibrateAtStartSetting();
StartPositionSetting(); StartPositionSetting();
ScalingSetting(); ScalingSetting();
FloatCorrectionSetting();
DontDestroySetting(); DontDestroySetting();
if (IsPrefab(humanoid)) if (IsPrefab(humanoid))
DisconnectInstancesSetting(); DisconnectInstancesSetting();
@ -770,6 +771,15 @@ namespace Passer {
scalingProp.intValue = (int)(HumanoidControl.ScalingType)EditorGUILayout.EnumPopup(text, (HumanoidControl.ScalingType)scalingProp.intValue); 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) { private void ShowTrackers(HumanoidControl humanoid, bool shown) {
foreach (Tracker tracker in humanoid.trackers) foreach (Tracker tracker in humanoid.trackers)
tracker.ShowTracker(shown); tracker.ShowTracker(shown);

View File

@ -2112,6 +2112,12 @@ namespace Passer.Humanoid {
// So probably this setting should only be used when using animations. // So probably this setting should only be used when using animations.
public bool useLegLengthCorrection = false; public bool useLegLengthCorrection = false;
private float legLengthCorrection = 0; private float legLengthCorrection = 0;
/// <summary>
/// Correct floating avatars when user is taller than the avatar
/// </summary>
public bool floatCorrection = false;
protected void CheckGrounded() { protected void CheckGrounded() {
Vector3 footBase = GetHumanoidPosition(); Vector3 footBase = GetHumanoidPosition();
//footBase += legLengthBias * Vector3.up; //footBase += legLengthBias * Vector3.up;
@ -2146,6 +2152,13 @@ namespace Passer.Humanoid {
legLengthCorrection = 0.99F * legLengthCorrection + 0.01F * footBoneDistance.y; 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) { public float GetDistanceToGroundAt(Vector3 position, float maxDistance) {