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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<Entity, float3> _prevPos;
|
||||
/// <summary>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).</summary>
|
||||
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<Entity, EnemyAnimCache> _prevPos;
|
||||
|
||||
protected override void OnCreate()
|
||||
{
|
||||
_prevPos = new NativeParallelHashMap<Entity, float3>(64, Allocator.Persistent);
|
||||
_prevPos = new NativeParallelHashMap<Entity, EnemyAnimCache>(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> 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<Entity, float3> prevPos;
|
||||
public NativeParallelHashMap<Entity, EnemyAnimCache> prevPos;
|
||||
public NativeParallelHashSet<Entity> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user