Fix: attack animation sank the model into the floor (Rukhanka partial-clip collapse)

An attack clip that keys ONLY the Root bone makes Rukhanka collapse every un-keyed bone (Hips/Spine/legs) to identity for the duration of the state -> the body folds halfway into the floor (player MeleeSwing + enemy Attack; writeDefaultValues does NOT prevent it -- confirmed since even a pure yaw, which is height-preserving, still sank). Fix: build the attack clips FROM the full idle pose (every bone keyed) + a Root YAW twist on top, so nothing is un-keyed. Applied to both runtime clips (PlayerMeleeSwing/EnemyAttackWindup) and both editor recipes (PlayerRigTools/EnemyRigTools) so rebuilds stay correct. Operator-verified in Play.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-11 00:35:39 -07:00
parent 12a18cc41c
commit 1224fd97f8
4 changed files with 261589 additions and 90 deletions
@@ -5,12 +5,13 @@ using UnityEngine;
namespace ProjectM.EditorTools
{
/// <summary>
/// MC-4 — builds the player's procedural MELEE SWING clip and adds the IsAttacking param + MeleeSwing state to
/// AC_PlayerTopDown. Mirrors EnemyRigTools' attack recipe (a Root-bone procedural clip — no authored Synty
/// Generic melee-swing clip exists; the slash-arc VFX in CombatFeedbackSystem carries the blade read). The clip
/// keys ONLY Root rotation (a yaw twist into the swing + a slight forward pitch), leaving the rig's authored
/// Root Y offset (feet-on-ground) untouched. PlayerAnimationDriveSystem drives IsAttacking from MeleeCombo.
/// Idempotent / re-runnable (menu: ProjectM/Animation).
/// MC-4 — builds the player's MELEE SWING clip + adds the IsAttacking param + MeleeSwing state to AC_PlayerTopDown.
/// The swing clip is built FROM the full idle pose (every bone keyed) + a Root YAW twist on top. A clip that keys
/// ONLY the Root makes Rukhanka collapse every un-keyed bone (Hips/Spine/legs) to identity for the state's
/// duration -> the body sinks into the floor; writeDefaultValues does NOT prevent it (2026-06-11 fix). Basing on
/// idle leaves nothing un-keyed; the Root yaw is a vertical-axis (height-preserving) twist that reads as a
/// horizontal slash, paired with the CombatFeedbackSystem slash-arc VFX. PlayerAnimationDriveSystem drives
/// IsAttacking from MeleeCombo. Idempotent / re-runnable (menu: ProjectM/Animation).
/// </summary>
public static class PlayerRigTools
{
@@ -20,37 +21,39 @@ namespace ProjectM.EditorTools
[MenuItem("ProjectM/Animation/Player - Build Melee Swing")]
public static void BuildPlayerMeleeSwing()
{
// Horizontal-cleave read: yaw the Root (wind back -> swing across -> recover) + a slight forward pitch.
// Root is the top of the Synty Generic rig; locomotion clips don't key Root, so no conflict and it
// returns to the authored pose on exit. Rotation-only (no position) so the baked Root Y offset stays.
var clip = new AnimationClip { frameRate = 30f };
var ac = AssetDatabase.LoadAssetAtPath<AnimatorController>(PlayerController);
if (ac == null) { Debug.LogError($"[PlayerRigTools] Controller missing: {PlayerController}"); return; }
var idle = FindIdleClip(ac);
if (idle == null) { Debug.LogError("[PlayerRigTools] No Idle-state clip to base the swing on."); return; }
// Full idle pose (every bone keyed) + a Root yaw twist. See the class summary for why a Root-only clip sinks.
var clip = AssetDatabase.LoadAssetAtPath<AnimationClip>(SwingClip);
if (clip == null) { clip = new AnimationClip { frameRate = 30f }; AssetDatabase.CreateAsset(clip, SwingClip); }
clip.ClearCurves();
foreach (var b in AnimationUtility.GetCurveBindings(idle))
{
if (b.path == "Root") continue; // the Root is driven below
AnimationUtility.SetEditorCurve(clip, b, AnimationUtility.GetEditorCurve(idle, b));
}
var yaw = new AnimationCurve(
new Keyframe(0f, 0f), new Keyframe(0.06f, -22f), new Keyframe(0.16f, 34f), new Keyframe(0.32f, 0f));
var pitch = new AnimationCurve(
new Keyframe(0f, 0f), new Keyframe(0.14f, 16f), new Keyframe(0.32f, 0f));
new Keyframe(0f, 0f), new Keyframe(0.06f, -25f), new Keyframe(0.16f, 48f), new Keyframe(0.30f, 0f));
AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve("Root", typeof(Transform), "localEulerAnglesRaw.y"), yaw);
AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve("Root", typeof(Transform), "localEulerAnglesRaw.x"), pitch);
var s = AnimationUtility.GetAnimationClipSettings(clip);
s.loopTime = false;
AnimationUtility.SetAnimationClipSettings(clip, s);
AssetDatabase.DeleteAsset(SwingClip);
AssetDatabase.CreateAsset(clip, SwingClip);
EditorUtility.SetDirty(clip);
AssetDatabase.SaveAssets();
var ac = AssetDatabase.LoadAssetAtPath<AnimatorController>(PlayerController);
if (ac == null) { Debug.LogError($"[PlayerRigTools] Controller missing: {PlayerController}"); return; }
if (!HasParam(ac, "IsAttacking"))
ac.AddParameter("IsAttacking", AnimatorControllerParameterType.Bool);
var sm = ac.layers[0].stateMachine;
var swingClipAsset = AssetDatabase.LoadAssetAtPath<AnimationClip>(SwingClip);
var swing = FindState(sm, "MeleeSwing");
if (swing == null)
{
swing = sm.AddState("MeleeSwing");
swing.writeDefaultValues = false; // partial (Root-only) clip: MUST be false, else WDV resets every un-keyed bone (Hips/Spine/legs) to identity and the body collapses into the floor
swing.writeDefaultValues = false;
var toSwing = sm.AddAnyStateTransition(swing);
toSwing.hasExitTime = false;
@@ -63,11 +66,18 @@ namespace ProjectM.EditorTools
fromSwing.duration = 0.10f;
fromSwing.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsAttacking");
}
swing.motion = swingClipAsset; // (re)point at the freshly-built clip
swing.motion = clip;
EditorUtility.SetDirty(ac);
AssetDatabase.SaveAssets();
Debug.Log("[PlayerRigTools] AC_PlayerTopDown: IsAttacking + MeleeSwing state built; PlayerMeleeSwing.anim created.");
Debug.Log("[PlayerRigTools] AC_PlayerTopDown: IsAttacking + idle-based MeleeSwing built (no un-keyed-bone collapse).");
}
static AnimationClip FindIdleClip(AnimatorController ac)
{
foreach (var c in ac.layers[0].stateMachine.states)
if (c.state.name == "Idle") return c.state.motion as AnimationClip;
return null;
}
static bool HasParam(AnimatorController ac, string name)