EerieVillage/Assets/Scripts/Gameplay/PlayerEnemyCollision.cs

52 lines
2.2 KiB
C#
Raw Normal View History

using Platformer.Core;
using Platformer.Mechanics;
using Platformer.Model;
using UnityEngine;
using static Platformer.Core.Simulation;
namespace Platformer.Gameplay
{
/// <summary>
/// Fired when a Player collides with an Enemy.
/// BT5-Dev 2단계 (2026-04-23): "위에서 밟기" 판정 폐기 → i-frame 체크 피격 로직.
/// PD 지시 2026-05-07: 밟기 공격 복원. 위에서 밟으면 적 즉사 + Player Bounce.
/// 측면·아래 충돌은 기존 i-frame 피격 로직 유지. 부활 직후 i-frame 동안에도 밟기는 가능.
/// </summary>
/// <typeparam name="EnemyCollision"></typeparam>
public class PlayerEnemyCollision : Simulation.Event<PlayerEnemyCollision>
{
public EnemyController enemy;
public PlayerController player;
/// <summary>BT5-Dev #16 — EnemyController.Update에서 측정한 Player·Enemy y 차 (밟기 판정 영역).</summary>
public float dyAtCollision;
// BT5-Dev #20 — Enemy.prefab 직렬화 영역 우회 영역 const 영역
// Player.height 1.15 + Enemy.height 1.26 → 발 닿는 영역 dy ≈ 1.0
const float STOMP_MIN_DY = 0.8f;
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
public override void Execute()
{
if (player == null || player.health == null || enemy == null) return;
// BT5-Dev #21 — 밟기 영역: Player 발이 Enemy 영역 위 (체공 상승·하강 모두 영역 — vy 조건 폐기)
// dy > STOMP_MIN_DY 영역에서 점프 영역 보장됨 (측면 닿음 영역 dy ≈ 0). vy<0 조건은 상승 시점 측면 피격 오인 발동
bool stomped = dyAtCollision > STOMP_MIN_DY;
Debug.Log($"[PEC] stomped={stomped} dy={dyAtCollision:F2} vy={player.velocity.y:F2} (thr>{STOMP_MIN_DY}) pInvuln={player.health.IsInvulnerable}");
if (stomped)
{
Schedule<EnemyDeath>().enemy = enemy;
player.Bounce(player.jumpTakeOffSpeed / 3f);
return;
}
// 측면·아래 충돌 — i-frame 적용 피격
if (player.health.IsInvulnerable) return;
player.health.Decrement();
}
}
}