From 0ff11fe2a97816d9294944930d0c06151480d9c6 Mon Sep 17 00:00:00 2001 From: Luis Gonzalez Date: Tue, 21 Jul 2026 00:28:11 -0700 Subject: [PATCH] Enemy hit-reacts: React/Stagger anim tiers off Health-drop edges (the Rukhanka-safe flinch) SwordCombat React (1.4x, 0.3s pulse) + Stagger (1.2x, 0.55s) as Any-State states on AC_EnemyTopDown via EnemyRigTools.WireEnemyHitReacts; driven by EnemyAnimationDriveSystem's cache (now Pos/Hp/ReactUntil/Heavy) off replicated Health drops. Windup-honesty gate: light reacts require !IsAttacking (a sub-poise hit never visually cancels a live windup); the heavy tier tracks the server's B2 poise break (stagger threshold 50 = finisher staggers, light flinches at the locked tuning). Knobs: HitReactSeconds (0=off) / HitStaggerSeconds / HitReactStaggerDamage. Replaces the review-cut positional vibrate (Rukhanka inverse-fold no-op). Co-Authored-By: Claude Fable 5 --- .../Animation/AC_EnemyTopDown.controller | 189 ++++++++++++++++++ .../Presentation/EnemyAnimationDriveSystem.cs | 50 ++++- .../Scripts/Client/Presentation/FeelConfig.cs | 12 ++ .../_Project/Scripts/Editor/EnemyRigTools.cs | 82 +++++++- 4 files changed, 325 insertions(+), 8 deletions(-) diff --git a/Assets/_Project/Animation/AC_EnemyTopDown.controller b/Assets/_Project/Animation/AC_EnemyTopDown.controller index c0ebb4589..612f1fe5a 100644 --- a/Assets/_Project/Animation/AC_EnemyTopDown.controller +++ b/Assets/_Project/Animation/AC_EnemyTopDown.controller @@ -27,6 +27,31 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &-8021912079140616559 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: IsHit + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 0} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 1 + serializedVersion: 3 + m_TransitionDuration: 0.12 + m_TransitionOffset: 0 + m_ExitTime: 0.9 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1102 &-6438350710411496961 AnimatorState: serializedVersion: 6 @@ -230,6 +255,18 @@ AnimatorController: m_DefaultInt: 0 m_DefaultBool: 0 m_Controller: {fileID: 9100000} + - m_Name: IsHit + m_Type: 4 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 9100000} + - m_Name: IsHitHeavy + m_Type: 4 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -366,10 +403,18 @@ AnimatorStateMachine: - serializedVersion: 1 m_State: {fileID: -6438350710411496961} m_Position: {x: 305, y: 195, z: 0} + - serializedVersion: 1 + m_State: {fileID: 5717376258036447168} + m_Position: {x: 340, y: 260, z: 0} + - serializedVersion: 1 + m_State: {fileID: 6961829067006426100} + m_Position: {x: 375, y: 325, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: - {fileID: 5014557051428573475} - {fileID: -4752793699339494306} + - {fileID: 9047675544309619590} + - {fileID: 6897112697058370456} m_EntryTransitions: [] m_StateMachineTransitions: {} m_StateMachineBehaviours: [] @@ -378,6 +423,91 @@ AnimatorStateMachine: m_ExitPosition: {x: 800, y: 120, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_DefaultState: {fileID: 8302574255206078140} +--- !u!1102 &5717376258036447168 +AnimatorState: + serializedVersion: 6 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: HitReact + m_Speed: 1.4 + m_CycleOffset: 0 + m_Transitions: + - {fileID: 9115654436388425902} + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: -5694488986427802680, guid: adc1feaf8563f6247989bffd0737b6ad, type: 3} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1101 &6897112697058370456 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: IsHit + m_EventTreshold: 0 + - m_ConditionMode: 1 + m_ConditionEvent: IsHitHeavy + m_EventTreshold: 0 + - m_ConditionMode: 2 + m_ConditionEvent: IsDead + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 6961829067006426100} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.05 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 +--- !u!1102 &6961829067006426100 +AnimatorState: + serializedVersion: 6 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: HitStagger + m_Speed: 1.2 + m_CycleOffset: 0 + m_Transitions: + - {fileID: -8021912079140616559} + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 8724492062134716513, guid: 3af9f677619822043a708e52c79ba040, type: 3} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: --- !u!1102 &8302574255206078140 AnimatorState: serializedVersion: 6 @@ -405,3 +535,62 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &9047675544309619590 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: IsHit + m_EventTreshold: 0 + - m_ConditionMode: 2 + m_ConditionEvent: IsHitHeavy + m_EventTreshold: 0 + - m_ConditionMode: 2 + m_ConditionEvent: IsAttacking + m_EventTreshold: 0 + - m_ConditionMode: 2 + m_ConditionEvent: IsDead + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 5717376258036447168} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.05 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 +--- !u!1101 &9115654436388425902 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: IsHit + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 0} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 1 + serializedVersion: 3 + m_TransitionDuration: 0.1 + m_TransitionOffset: 0 + m_ExitTime: 0.9 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 diff --git a/Assets/_Project/Scripts/Client/Presentation/EnemyAnimationDriveSystem.cs b/Assets/_Project/Scripts/Client/Presentation/EnemyAnimationDriveSystem.cs index fc7e85e77..da7f7e107 100644 --- a/Assets/_Project/Scripts/Client/Presentation/EnemyAnimationDriveSystem.cs +++ b/Assets/_Project/Scripts/Client/Presentation/EnemyAnimationDriveSystem.cs @@ -42,13 +42,24 @@ namespace ProjectM.Client static readonly FastAnimatorParameter k_Speed = new FastAnimatorParameter("Speed"); static readonly FastAnimatorParameter k_IsAttacking = new FastAnimatorParameter("IsAttacking"); static readonly FastAnimatorParameter k_IsDead = new FastAnimatorParameter("IsDead"); // B3: the controller's Death state existed but was never driven + static readonly FastAnimatorParameter k_IsHit = new FastAnimatorParameter("IsHit"); // 07-21 hit-react (G5): pulsed off replicated Health-drop edges + static readonly FastAnimatorParameter k_IsHitHeavy = new FastAnimatorParameter("IsHitHeavy"); // heavy tier -> HitStagger (aligns with the server's B2 poise break) - // prevPos cache (per Husk Entity). Pruned every frame (a vanished Husk = a server-authoritative death). - NativeParallelHashMap _prevPos; + /// 07-21: per-Husk anim cache -- position (velocity derivation), Health (the hit-react damage + /// edge), and the active flinch pulse. Pruned every frame (a vanished Husk = a server-authoritative death). + struct EnemyAnimCache + { + public float3 Pos; + public float Hp; + public float ReactUntil; // wall-clock ElapsedTime the flinch pulse ends (0 = none) + public bool Heavy; // this pulse is the stagger tier + } + + NativeParallelHashMap _prevPos; protected override void OnCreate() { - _prevPos = new NativeParallelHashMap(64, Allocator.Persistent); + _prevPos = new NativeParallelHashMap(64, Allocator.Persistent); } protected override void OnDestroy() @@ -65,6 +76,12 @@ namespace ProjectM.Client var job = new EnemyDriveJob { moveX = k_MoveX, moveZ = k_MoveZ, speed = k_Speed, isAttacking = k_IsAttacking, isDead = k_IsDead, + isHit = k_IsHit, isHitHeavy = k_IsHitHeavy, + // 07-21 hit-react knobs (read main-thread, passed by value -- never FeelConfig inside Burst) + el = (float)SystemAPI.Time.ElapsedTime, + reactSeconds = math.max(0f, FeelConfig.HitReactSeconds), + staggerSeconds = math.max(0f, FeelConfig.HitStaggerSeconds), + staggerDamage = math.max(1f, FeelConfig.HitReactStaggerDamage), dt = dt, prevPos = _prevPos, seen = seen, @@ -92,11 +109,12 @@ namespace ProjectM.Client [WithAll(typeof(EnemyTag))] partial struct EnemyDriveJob : IJobEntity { - public FastAnimatorParameter moveX, moveZ, speed, isAttacking, isDead; + public FastAnimatorParameter moveX, moveZ, speed, isAttacking, isDead, isHit, isHitHeavy; + public float el, reactSeconds, staggerSeconds, staggerDamage; // 07-21 hit-react (reactSeconds 0 = off) [Unity.Collections.ReadOnly] public ComponentLookup isLunging; // A7: a lunge has no AttackWindup; OR it in so the boss/Charger attack anim plays during the committed lunge public float dt; - public NativeParallelHashMap prevPos; + public NativeParallelHashMap prevPos; public NativeParallelHashSet seen; void Execute( @@ -111,9 +129,23 @@ namespace ProjectM.Client seen.Add(e); float3 cur = xform.Position; float3 vel = float3.zero; + var cache = new EnemyAnimCache { Pos = cur, Hp = health.Current }; if (prevPos.TryGetValue(e, out var prev)) - vel = (cur - prev) / dt; - prevPos[e] = cur; + { + vel = (cur - prev.Pos) / dt; + cache.ReactUntil = prev.ReactUntil; + cache.Heavy = prev.Heavy; + // 07-21 hit-react (G5): a replicated Health DROP on a living Husk = the flinch edge. The heavy + // tier (>= staggerDamage, e.g. the finisher) plays the stagger -- aligned with the server's B2 + // poise break, so the anim never claims an interrupt the sim didn't make. + float drop = prev.Hp - health.Current; + if (drop > 0.01f && health.Current > 0f && reactSeconds > 0f) + { + cache.Heavy = drop >= staggerDamage; + cache.ReactUntil = el + (cache.Heavy ? staggerSeconds : reactSeconds); + } + } + prevPos[e] = cache; float2 facing = AnimParamMath.PlanarForward(xform.Rotation); float3 p = AnimParamMath.LocomotionParams(vel, facing, stats.MoveSpeed); @@ -130,6 +162,10 @@ namespace ProjectM.Client if (a.HasParameter(speed)) a.SetParameterValue(speed, p.z); if (a.HasParameter(isAttacking)) a.SetParameterValue(isAttacking, attacking); if (a.HasParameter(isDead)) a.SetParameterValue(isDead, dead); + // 07-21 hit-react pulse (a corpse never flinches; the controller adds the windup-honesty gate). + bool hitActive = !dead && cache.ReactUntil > 0f && el < cache.ReactUntil; + if (a.HasParameter(isHit)) a.SetParameterValue(isHit, hitActive); + if (a.HasParameter(isHitHeavy)) a.SetParameterValue(isHitHeavy, hitActive && cache.Heavy); } } } diff --git a/Assets/_Project/Scripts/Client/Presentation/FeelConfig.cs b/Assets/_Project/Scripts/Client/Presentation/FeelConfig.cs index bd7d605e4..0872fead3 100644 --- a/Assets/_Project/Scripts/Client/Presentation/FeelConfig.cs +++ b/Assets/_Project/Scripts/Client/Presentation/FeelConfig.cs @@ -163,6 +163,15 @@ namespace ProjectM.Client /// Camera hold frames when the melee FINISHER lands (07-20 G5 impact ladder; light hits use HitStopMaxFrames). public static int FinisherHoldFrames; + // ---- 07-21 enemy hit-reacts (G5; the Rukhanka-safe flinch that replaced the cut vibrate) ---- + /// Seconds the light flinch pulse holds (0 = hit-reacts OFF). + public static float HitReactSeconds; + /// Seconds the heavy stagger pulse holds. + public static float HitStaggerSeconds; + /// Health drop at/above which the react upgrades to the STAGGER tier (keep aligned with the + /// server's B2 poise math: the finisher should stagger, a light hit should not). + public static float HitReactStaggerDamage; + /// Master gate for gamepad rumble (no-op on KBM). public static bool RumbleEnabled; @@ -290,6 +299,9 @@ namespace ProjectM.Client MeleeArcIntensity = 0.8f; // 07-21 HEAVY LOCK: the weapon is the read, the arc recedes further MeleeArcBubbles = 6; FinisherHoldFrames = 7; // 07-21 HEAVY LOCK: a fatter finisher beat (~117ms, still under the 8-frame ladder cap) + HitReactSeconds = 0.3f; // 07-21: light flinch pulse (clip plays at 1.4x -> the peak lands inside it) + HitStaggerSeconds = 0.55f; // heavy stagger pulse + HitReactStaggerDamage = 50f; // finisher (63 seeded) staggers, light (42) flinches -- tracks B2 poise RumbleEnabled = true; diff --git a/Assets/_Project/Scripts/Editor/EnemyRigTools.cs b/Assets/_Project/Scripts/Editor/EnemyRigTools.cs index 8ddf2a20d..efac301ea 100644 --- a/Assets/_Project/Scripts/Editor/EnemyRigTools.cs +++ b/Assets/_Project/Scripts/Editor/EnemyRigTools.cs @@ -26,6 +26,8 @@ namespace ProjectM.EditorTools const string PlayerController = "Assets/_Project/Animation/AC_PlayerTopDown.controller"; const string EnemyController = "Assets/_Project/Animation/AC_EnemyTopDown.controller"; const string AttackClip = "Assets/_Project/Animation/EnemyAttackWindup.anim"; + const string HitReactFbx = "Assets/Synty/AnimationSwordCombat/Animations/Polygon/Hit/HitReact/A_Hit_F_React_Sword.fbx"; + const string HitStaggerFbx = "Assets/Synty/AnimationSwordCombat/Animations/Polygon/Hit/HitStagger/A_Hit_F_Stagger_Sword.fbx"; const string WerewolfAtlas = "Assets/Synty/PolygonWerewolf/Textures/PolygonWerewolf_01_A.png"; const string KaijuAtlas = "Assets/Synty/PolygonKaiju/Textures/PolygonKaiju_01.png"; @@ -364,5 +366,83 @@ namespace ProjectM.EditorTools } Debug.LogWarning($"[EnemyRigTools] Field/prop '{name}' not found on {o.GetType().Name}."); } - } + + + /// 07-21 hit-react pass (guidelines G5; the Rukhanka-safe flinch replacing the cut vibrate): + /// adds IsHit/IsHitHeavy params + HitReact (light flinch) and HitStagger (heavy) Any-State states to + /// AC_EnemyTopDown, pulsed by EnemyAnimationDriveSystem off replicated Health-drop edges. HONESTY GATE: + /// the light react requires IsAttacking == false so a sub-poise hit never visually cancels a windup the + /// server is still running (the telegraph must not lie); a HEAVY hit staggers unconditionally, which + /// aligns with the server's B2 poise break (finisher knockback >= the stagger threshold zeroes the + /// windup). Idempotent / re-runnable. + [MenuItem("ProjectM/Animation/Enemy - Wire Hit Reacts (LANTERN)")] + public static void WireEnemyHitReacts() + { + var ac = AssetDatabase.LoadAssetAtPath(EnemyController); + if (ac == null) { Debug.LogError($"[EnemyRigTools] Controller missing: {EnemyController}"); return; } + + AnimationClip Clip(string fbxPath, string clipName) + { + foreach (var o in AssetDatabase.LoadAllAssetsAtPath(fbxPath)) + if (o is AnimationClip c && c.name == clipName) return c; + Debug.LogError($"[EnemyRigTools] Clip missing: {fbxPath} -> {clipName}"); + return null; + } + var react = Clip(HitReactFbx, "A_Hit_F_React_Sword"); + var stagger = Clip(HitStaggerFbx, "A_Hit_F_Stagger_Sword"); + if (react == null || stagger == null) return; + + void EnsureParam(string n) + { + foreach (var p in ac.parameters) if (p.name == n) return; + ac.AddParameter(n, AnimatorControllerParameterType.Bool); + } + EnsureParam("IsHit"); + EnsureParam("IsHitHeavy"); + + var sm = ac.layers[0].stateMachine; + AnimatorState Find(string n) + { + foreach (var cs in sm.states) if (cs.state.name == n) return cs.state; + return null; + } + + var hitReact = Find("HitReact"); + if (hitReact == null) + { + hitReact = sm.AddState("HitReact"); + var to = sm.AddAnyStateTransition(hitReact); + to.hasExitTime = false; to.duration = 0.05f; to.canTransitionToSelf = false; + to.AddCondition(AnimatorConditionMode.If, 0f, "IsHit"); + to.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsHitHeavy"); + to.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsAttacking"); // honesty: never cancel a live windup visual + to.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsDead"); + var ex = hitReact.AddExitTransition(); + ex.hasExitTime = false; ex.duration = 0.10f; + ex.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsHit"); + } + hitReact.motion = react; + hitReact.speed = 1.4f; // 0.83s clip -> the flinch peak inside the ~0.3s pulse + + var hitStagger = Find("HitStagger"); + if (hitStagger == null) + { + hitStagger = sm.AddState("HitStagger"); + var to = sm.AddAnyStateTransition(hitStagger); + to.hasExitTime = false; to.duration = 0.05f; to.canTransitionToSelf = false; + to.AddCondition(AnimatorConditionMode.If, 0f, "IsHit"); + to.AddCondition(AnimatorConditionMode.If, 0f, "IsHitHeavy"); // heavy overrides even a windup (server poise broke it) + to.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsDead"); + var ex = hitStagger.AddExitTransition(); + ex.hasExitTime = false; ex.duration = 0.12f; + ex.AddCondition(AnimatorConditionMode.IfNot, 0f, "IsHit"); + } + hitStagger.motion = stagger; + hitStagger.speed = 1.2f; // 1.07s clip -> the lurch inside the ~0.55s pulse + + EditorUtility.SetDirty(ac); + AssetDatabase.SaveAssets(); + Debug.Log("[EnemyRigTools] Hit reacts wired: HitReact (light, windup-honest) + HitStagger (heavy) on AC_EnemyTopDown."); + } +} }