Project_WL/Assets/WL/Combat/AttackRootMotion.cs

146 lines
7.3 KiB
C#
Raw Permalink Normal View History

WL 리뉴얼 세션 2026-09-06~07 (#760~#800) — 전투·배경·UI·타격감 (조직 PD 로그 #746~#800 · 대화로그 §14~§24) - 전투: Knight@Attack1~3_S 3콤보(4 컨트롤러·클래스별 서브클립) · 타겟팅 4규칙(정면 우선·재타겟·즉시 공격·어그로 금지 · WLTargetingSettings) · 대쉬 후 공격(Stander@Chase_Start · DashDriver · 5 m · 사정거리+0.8 · 근거리 적 우선) · 공격 이동 FrameTable(발 접지 실측 표 · AttackRootMotion) · 충돌 반경/투사체 0.3 배(WLCollisionTuning) · 무적(임시)·펫 금지(WLGameplaySettings) - 검기: NamuFX Slash_B 배리언트 Effect_WLSwingArc 원 피팅 정합 배치 + 캘리브레이션(SlashArcMeasure · SlashTrailSettings) · 찌르기 Effect_WLStab 대기 · 램프 리본(BladeTrail · WL_BladeRibbon.shader · T_WL_BladeRibbonRamp) 보존(drawRibbon 0) - 타격감: Assets/WL/Feel(WLHitFeel · 히트스톱 0.03 · 셰이크 0.10 m · 몹 펀치 1.12 · Actor.Get_Damage 훅 1줄 · 원본 RealCamera 셰이크 결함 대체) - 배경/맵: LMHPOLY Demo_01~10 → WL_Nature01~10(프리팹·씬·NavMesh·스포너·BattleMapConfig) · 물(ToonWaterU) · 포스트 블룸 0.9/0.3 · 잔디(BruteForce·드레싱) 제거 · 마젠타 머티리얼 URP 변환 - UI: 세로 HUD(WL_HUD · 하단 5메뉴 폭 전체 · 채팅/전투 패드 숨김 · WLIngameUiOverride) · Title/TitleInfo 1080×1920 Expand + 배경 높이 fit(WLBackgroundFit) · 로딩 SortOrder_5(WLRawImageAspectSync · 초점표 8장) · Loading1~8 ASTC 6×6 - 도구: AgentScripts/*(LightProbe · WL_MapSwitch · WL760~WL800 프로브/집행/검증 · 상단 사용법 주석) · 에디터 락 프로토콜 파일(staging) - 제외(별도 커밋 예정): Assets/LMHPOLY(703 MB) · Assets/Feel(422 MB) · Assets/Shinabro(300 MB) — 에셋 스토어/구 WL 팩 원본 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-06 23:24:25 +00:00
// ─────────────────────────────────────────────────────────────────────────────
// AttackRootMotion.cs — 공격 클립의 이동을 액터 이동으로 재현 (PD #789 · #791 · 2026-09-07)
//
// 모드(WLCombatMotionSettings.attackMoveMode):
// · FrameTable(기본 · #791): 클립별 "프레임 → 전진(cm)" 표(발 접지 실측으로 도출)를 클립 정규화 시간으로 재생.
// 발이 땅에 붙어 있는 구간엔 0, 발이 공중에 있거나 내딛는 구간에만 전진 → 발 슬라이딩이 없다.
// 힘민지 원본 `Interpolation` 이벤트(프레임 목록 + 프레임당 값)와 같은 개념을 WL 설정 SO 로 옮긴 것(FBX 이벤트 무수정).
// · ClipRootMotion(#789): animator.deltaPosition(RootT) 재생. Knight 클립은 상체 러닝(hips 33 cm 전후)이 루트에 섞여
// 접지 발이 30 cm 미끄러진다(2026-09-07 실측) → 기본에서 제외, 비교용으로 보존.
// · FixedStep(#762): AttackStepDriver + 원본 Set_Move.
// 적용: 공격 상태에서만 · NavMeshAgent.Move · 대상 stopDistance 관통 방지 · 조이스틱 입력 시 중단 없음(공격 중엔 입력 무시가 원본 동작).
// ─────────────────────────────────────────────────────────────────────────────
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
namespace WL.Combat
{
[DisallowMultipleComponent]
public sealed class AttackRootMotion : MonoBehaviour
{
private PCActor _pc;
private Animator _anim;
private NavMeshAgent _agent;
private WLCombatMotionSettings _cfg;
// FrameTable 상태
private int _tableClipHash; // 현재 재생 중인 표의 클립(상태) 식별
private int _tableLastFrame = -1; // 마지막으로 처리한 프레임 인덱스
private float _tableLastNorm = -1f;
// ── 검증용 정적 카운터 ──
public static int EntryCount, ApplyCount;
public static float LastFrameDelta, SwingAccum, RawAccum;
public static string LastInfo = "";
public static bool HandlesAttackMove(PCActor pc)
{
var cfg = WLCombatMotionSettings.Instance;
return pc != null && cfg != null && cfg.attackMoveMode != AttackMoveMode.FixedStep;
}
public static void Ensure(PCActor pc)
{
if (pc == null || pc.m_animation == null) return;
var cfg = WLCombatMotionSettings.Instance;
if (cfg == null) return;
var host = pc.m_animation.gameObject;
var rm = host.GetComponent<AttackRootMotion>();
if (rm == null) rm = host.AddComponent<AttackRootMotion>();
rm._pc = pc; rm._anim = pc.m_animation; rm._agent = pc.Get_Agent(); rm._cfg = cfg;
rm._anim.applyRootMotion = cfg.attackMoveMode == AttackMoveMode.ClipRootMotion;
}
private void OnDisable() { if (_anim != null) _anim.applyRootMotion = false; }
private void OnAnimatorMove()
{
EntryCount++;
if (_pc == null || _anim == null) return;
var cfg = _cfg != null ? _cfg : WLCombatMotionSettings.Instance;
if (cfg == null) return;
if (cfg.attackMoveMode != AttackMoveMode.ClipRootMotion)
{
if (_anim.applyRootMotion) _anim.applyRootMotion = false;
return;
}
if (!_anim.applyRootMotion) _anim.applyRootMotion = true;
if (!Gate(cfg)) return;
Vector3 d = _anim.deltaPosition; d.y = 0f;
RawAccum += d.magnitude;
if (d.sqrMagnitude < 1e-12f) return;
Apply(d * Mathf.Max(cfg.rootMotionScale, 0f), cfg, true);
}
private void LateUpdate()
{
if (_pc == null || _anim == null) return;
var cfg = _cfg != null ? _cfg : WLCombatMotionSettings.Instance;
if (cfg == null || cfg.attackMoveMode != AttackMoveMode.FrameTable) return;
if (!Gate(cfg)) { _tableLastFrame = -1; _tableClipHash = 0; return; }
var st = _anim.GetCurrentAnimatorStateInfo(0);
var ci = _anim.GetCurrentAnimatorClipInfo(0);
if (ci.Length == 0 || ci[0].clip == null) return;
var clip = ci[0].clip;
var table = cfg.FindFrameTable(clip.name);
if (table == null) return;
float norm = st.normalizedTime - Mathf.Floor(st.normalizedTime);
int totalFrames = Mathf.Max(1, Mathf.RoundToInt(clip.frameRate * clip.length));
int frame = Mathf.Clamp((int)(norm * totalFrames), 0, totalFrames);
int hash = st.fullPathHash;
if (hash != _tableClipHash || norm < _tableLastNorm - 0.5f) { _tableClipHash = hash; _tableLastFrame = frame - 1; }
_tableLastNorm = norm;
if (frame <= _tableLastFrame) return;
// 놓친 프레임까지 합산(프레임 드랍 보정 · 원본 Co_Interpolation 과 같은 규약)
float cm = 0f;
for (int f = _tableLastFrame + 1; f <= frame; f++) cm += table.ValueAt(f);
_tableLastFrame = frame;
if (cm <= 0f) return;
Vector3 fwd = _pc.transform.forward; fwd.y = 0f;
if (fwd.sqrMagnitude < 1e-6f) return;
Apply(fwd.normalized * (cm * 0.01f * Mathf.Max(cfg.frameTableScale, 0f)), cfg, false);
}
private bool Gate(WLCombatMotionSettings cfg)
{
if (_agent == null || !_agent.enabled || !_agent.isOnNavMesh) return false;
if (!_pc.WL_CanAttackStep()) return false;
if (DashDriver.IsDashingNow(_pc)) return false;
return true;
}
private void Apply(Vector3 d, WLCombatMotionSettings cfg, bool clampSpeed)
{
if (clampSpeed)
{
float maxStep = Mathf.Max(cfg.rootMotionMaxSpeed, 0.1f) * Mathf.Max(Time.deltaTime, 1e-4f);
if (d.magnitude > maxStep) d = d.normalized * maxStep;
}
if (!cfg.rootMotionAllowBackward)
{
Vector3 f = _pc.transform.forward; f.y = 0f;
if (f.sqrMagnitude > 1e-6f) { f.Normalize(); float along = Vector3.Dot(d, f); if (along < 0f) d -= f * along; }
}
var target = _pc.Get_Target();
if (target != null && !target.IsDead() && cfg.attackStepStopDistance > 0f)
{
Vector3 to = target.Get_position() - _pc.transform.position; to.y = 0f;
float dist = to.magnitude;
if (dist > 1e-4f)
{
Vector3 n = to / dist; float along = Vector3.Dot(d, n);
if (along > 0f && dist - along < cfg.attackStepStopDistance)
{ float allowed = Mathf.Max(dist - cfg.attackStepStopDistance, 0f); d -= n * (along - allowed); }
}
}
if (d.sqrMagnitude < 1e-12f) return;
_agent.Move(d);
ApplyCount++; LastFrameDelta = d.magnitude; SwingAccum += d.magnitude;
}
}
}