Fix unstable humanoid pose when using pose and simpleSpineIK

This commit is contained in:
Pascal Serrarens 2023-09-19 21:15:29 +02:00
parent 411b97e33d
commit 43edc40b53
6 changed files with 38 additions and 33 deletions

View File

@ -855,6 +855,7 @@ namespace Passer {
else { else {
humanoid.pose.Show(humanoid); humanoid.pose.Show(humanoid);
humanoid.CopyRigToTargets(); humanoid.CopyRigToTargets();
humanoid.MatchTargetsToAvatar();
} }
} }

View File

@ -63,9 +63,9 @@ namespace Passer {
}; };
} }
#endregion #endregion
#region Disable #region Disable
public void OnDisable() { public void OnDisable() {
if (humanoid == null) { if (humanoid == null) {
// This target is not connected to a humanoid, so we delete it // This target is not connected to a humanoid, so we delete it
@ -82,9 +82,9 @@ namespace Passer {
foreach (TargetProps props in allProps) foreach (TargetProps props in allProps)
props.SetSensor2Target(); props.SetSensor2Target();
} }
#endregion #endregion
#region Inspector #region Inspector
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
if (footTarget == null || humanoid == null) if (footTarget == null || humanoid == null)
return; return;
@ -142,7 +142,7 @@ namespace Passer {
return foundHumanoid; return foundHumanoid;
} }
#region Sensors #region Sensors
private static bool showControllers = true; private static bool showControllers = true;
private void ControllerInspectors(FootTarget footTarget) { private void ControllerInspectors(FootTarget footTarget) {
showControllers = EditorGUILayout.Foldout(showControllers, "Controllers", true); showControllers = EditorGUILayout.Foldout(showControllers, "Controllers", true);
@ -157,9 +157,9 @@ namespace Passer {
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
} }
#endregion #endregion
#region Configuration #region Configuration
private void InitConfiguration(FootTarget footTarget) { private void InitConfiguration(FootTarget footTarget) {
if (footTarget.humanoid.avatarRig == null) if (footTarget.humanoid.avatarRig == null)
return; return;
@ -200,7 +200,7 @@ namespace Passer {
UpdateToesBones(target.toes); UpdateToesBones(target.toes);
} }
#region UpperLeg #region UpperLeg
//private string upperLegXname; //private string upperLegXname;
//private SerializedProperty upperLegMinX; //private SerializedProperty upperLegMinX;
//private SerializedProperty upperLegMaxX; //private SerializedProperty upperLegMaxX;
@ -276,9 +276,9 @@ namespace Passer {
//upperLeg.bone.maxAngles.z = upperLegMaxZ.floatValue; //upperLeg.bone.maxAngles.z = upperLegMaxZ.floatValue;
} }
#endregion #endregion
#region LowerLeg #region LowerLeg
//private string lowerLegYname; //private string lowerLegYname;
//private SerializedProperty lowerLegMinX; //private SerializedProperty lowerLegMinX;
//private SerializedProperty lowerLegMaxX; //private SerializedProperty lowerLegMaxX;
@ -326,9 +326,9 @@ namespace Passer {
//lowerLeg.bone.minAngles.x = lowerLegMinX.floatValue; //lowerLeg.bone.minAngles.x = lowerLegMinX.floatValue;
//lowerLeg.bone.maxAngles.x = lowerLegMaxX.floatValue; //lowerLeg.bone.maxAngles.x = lowerLegMaxX.floatValue;
} }
#endregion #endregion
#region Foot #region Foot
//private string footXname; //private string footXname;
//private SerializedProperty footMinX; //private SerializedProperty footMinX;
//private SerializedProperty footMaxX; //private SerializedProperty footMaxX;
@ -390,9 +390,9 @@ namespace Passer {
//foot.bone.minAngles.z = footMinZ.floatValue; //foot.bone.minAngles.z = footMinZ.floatValue;
//foot.bone.maxAngles.z = footMaxZ.floatValue; //foot.bone.maxAngles.z = footMaxZ.floatValue;
} }
#endregion #endregion
#region Toes #region Toes
//private string toesXname; //private string toesXname;
//private SerializedProperty toesMinX; //private SerializedProperty toesMinX;
//private SerializedProperty toesMaxX; //private SerializedProperty toesMaxX;
@ -441,10 +441,10 @@ namespace Passer {
//toes.bone.maxAngles.x = toesMaxX.floatValue; //toes.bone.maxAngles.x = toesMaxX.floatValue;
} }
#endregion #endregion
#endregion #endregion
#region Settings #region Settings
private SerializedProperty rotationSpeedLimitationProp; private SerializedProperty rotationSpeedLimitationProp;
private SerializedProperty slidePreventionProp; private SerializedProperty slidePreventionProp;
@ -470,9 +470,9 @@ namespace Passer {
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
} }
#endregion #endregion
#region Events #region Events
protected SerializedProperty groundEventProp; protected SerializedProperty groundEventProp;
@ -534,11 +534,11 @@ namespace Passer {
// } // }
//} //}
#endregion #endregion
#endregion #endregion
#region Scene #region Scene
public void OnSceneGUI() { public void OnSceneGUI() {
if (footTarget == null || humanoid == null) if (footTarget == null || humanoid == null)
@ -551,12 +551,13 @@ namespace Passer {
humanoid.pose.UpdatePose(humanoid); humanoid.pose.UpdatePose(humanoid);
else { else {
humanoid.pose.Show(humanoid); humanoid.pose.Show(humanoid);
footTarget.CopyRigToTarget(); humanoid.CopyRigToTargets();
humanoid.MatchTargetsToAvatar();
} }
} }
// update the target rig from the current foot target // update the target rig from the current foot target
footTarget.CopyTargetToRig(); humanoid.CopyTargetsToRig();
// update the avatar bones from the target rig // update the avatar bones from the target rig
humanoid.UpdateMovements(); humanoid.UpdateMovements();
// match the target rig with the new avatar pose // match the target rig with the new avatar pose
@ -568,7 +569,7 @@ namespace Passer {
humanoid.UpdateSensorsFromTargets(); humanoid.UpdateSensorsFromTargets();
} }
#endregion #endregion
public abstract class TargetProps { public abstract class TargetProps {
public SerializedProperty enabledProp; public SerializedProperty enabledProp;

View File

@ -695,12 +695,13 @@ namespace Passer.Humanoid {
humanoid.pose.UpdatePose(humanoid); humanoid.pose.UpdatePose(humanoid);
else { else {
humanoid.pose.Show(humanoid); humanoid.pose.Show(humanoid);
handTarget.CopyRigToTarget(); humanoid.CopyRigToTargets();
humanoid.MatchTargetsToAvatar();
} }
} }
// update the target rig from the current hand target // update the target rig from the current hand target
handTarget.CopyTargetToRig(); humanoid.CopyTargetsToRig();
// update the avatar bones from the target rig // update the avatar bones from the target rig
humanoid.UpdateMovements(); humanoid.UpdateMovements();
// match the target rig with the new avatar pose // match the target rig with the new avatar pose

View File

@ -275,7 +275,7 @@ namespace Passer.Humanoid {
if (headTarget.humanoid == null) if (headTarget.humanoid == null)
return; return;
SerializedProperty animatorProp = serializedObject.FindProperty(nameof(HeadTarget.headAnimator)+ "." +nameof(HeadTarget.headAnimator.enabled)); SerializedProperty animatorProp = serializedObject.FindProperty(nameof(HeadTarget.headAnimator) + "." + nameof(HeadTarget.headAnimator.enabled));
if (animatorProp != null && headTarget.humanoid.animatorEnabled) { if (animatorProp != null && headTarget.humanoid.animatorEnabled) {
GUIContent text = new GUIContent( GUIContent text = new GUIContent(
@ -482,12 +482,13 @@ namespace Passer.Humanoid {
humanoid.pose.UpdatePose(humanoid); humanoid.pose.UpdatePose(humanoid);
else { else {
humanoid.pose.Show(humanoid); humanoid.pose.Show(humanoid);
headTarget.CopyRigToTarget(); humanoid.CopyRigToTargets();
humanoid.MatchTargetsToAvatar();
} }
} }
// update the target rig from the current head target // update the target rig from the current head target
headTarget.CopyTargetToRig(); humanoid.CopyTargetToRig();
// update the avatar bones from the target rig // update the avatar bones from the target rig
humanoid.UpdateMovements(); humanoid.UpdateMovements();
// match the target rig with the new avatar pose // match the target rig with the new avatar pose

View File

@ -276,12 +276,13 @@ namespace Passer {
humanoid.pose.UpdatePose(humanoid); humanoid.pose.UpdatePose(humanoid);
else { else {
humanoid.pose.Show(humanoid); humanoid.pose.Show(humanoid);
hipsTarget.CopyRigToTarget(); humanoid.CopyRigToTargets();
humanoid.MatchTargetsToAvatar();
} }
} }
// update the target rig from the current hips target // update the target rig from the current hips target
hipsTarget.CopyTargetToRig(); humanoid.CopyTargetsToRig();
// update the avatar bones to match the target rig // update the avatar bones to match the target rig
humanoid.UpdateMovements(); humanoid.UpdateMovements();
// match the target rig with the new avatar pose // match the target rig with the new avatar pose

View File

@ -751,7 +751,7 @@ namespace Passer.Humanoid {
} }
/// <summary>Copies the pose of the target rig to the avatar</summary> /// <summary>Copies the pose of the target rig to the avatar</summary>
private void CopyTargetsToRig() { public void CopyTargetsToRig() {
hipsTarget.CopyTargetToRig(); hipsTarget.CopyTargetToRig();
headTarget.CopyTargetToRig(); headTarget.CopyTargetToRig();
leftHandTarget.CopyTargetToRig(); leftHandTarget.CopyTargetToRig();