BT5-Dev #75: 발판 시스템 영구 마무리 — 시행착오 주석 정리·dead code 제거
PD 명시 (2026-05-08): "플레이어 조작 시스템 완성. 시행착오로 불필요하게 생성된 코드·작업물 제거 + 최신 상태로만 깔끔하게" 정리 영역: 1. GameOptimizer.cs (Write 전체 재작성): - 헤더 주석 — BT5-Dev 발판 시스템 영구 영역 명시 + 동작 요약 5단계 - BT34·BT46·BT66·BT67·BT48·BT63·BT68 시행착오 주석 영역 통합 정리 - Debug.Log 영역 통합 1행 ([GameOptimizer] 출력) - IsSmallAirPlatform 헬퍼 영역 보존 (BT48 휴리스틱 사용 중) 2. PlayerController.cs (Edit 부분 정리): - dropThroughTimer·jumpAscentTimer 변수 영역 주석 정리 - OnCollisionEnter2D BT30-Collide 진단 Debug.Log 영역 폐기 (시행착오) - BT69·BT70·BT71·BT72·BT73·BT74 시행착오 주석 영역 통합 정리 - UpdateContactFilterForDropThrough 영역 메서드 docstring 추가 3. KinematicObject.cs (Edit 부분 정리): - BT68 X·Y 분리 영역 주석 정리 영구 채택 영역: - R2 (BT66): AutoForeground GameObject 분리 + PD Foreground = 가림막 시각만 - BT67: AutoForeground transform 동기화 (PD Foreground·Level 영역과 동일) - BT68: KinematicObject X·Y 분리 + GameOptimizer TileGround* 자동 분류 제외 - BT69~BT74: Drop-Through (Down + Jump) Input 패턴 + 가장자리 jitter 차단 플레이어 조작 시스템 완성: - 발판 위 착지·점프 통과·자유 이동 - Down + Jump = Drop-Through (발판 위만) - 전진 점프 시 앞 벽 hit + 위로 점프 보존 - 대각선 벽 통과 X (TileGround* Level 잔존) - 발판 가장자리 jitter 차단 (3점 Raycast + 밀림 강제 Drop-Through)
This commit is contained in:
parent
5b199cbe6f
commit
2ebacf636c
|
|
@ -4,8 +4,19 @@ using UnityEngine.Tilemaps;
|
||||||
namespace Platformer.Mechanics
|
namespace Platformer.Mechanics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 게임 시작 시 프레임·렌더·물리 영역 기본 최적화 + One-Way Platform 자동 적용.
|
/// 게임 시작 시 프레임·렌더·물리 기본 최적화 + One-Way Platform 자동 적용.
|
||||||
/// PD 지시 2026-05-07 — 스크롤 버벅임 보완 + 점프·이동 시 지형 통과(One-Way Platform).
|
/// BT5-Dev 발판 시스템 영구 영역 (2026-05-08 PD 정합 마무리).
|
||||||
|
///
|
||||||
|
/// 동작 요약:
|
||||||
|
/// 1. Layer Matrix: Player(13) ↔ Enemy(14) 충돌 OFF.
|
||||||
|
/// 2. Level Tilemap = Layer 0 (지면·벽 영구 충돌). 그 외 비-trigger Collider2D = Layer 16 강제.
|
||||||
|
/// 3. PD Foreground GameObject = 가림막 시각만 (TilemapCollider2D 제거).
|
||||||
|
/// 4. AutoForeground GameObject (Grid 자식·Tilemap·TilemapCollider·Layer 16) = 자동 분류 발판.
|
||||||
|
/// 5. 자동 분류 (Level → AutoForeground):
|
||||||
|
/// - colliderType=None Tile (tree·plant·fence·house) 제외
|
||||||
|
/// - 이름 prefix "TileGround" Tile (지면·벽) 제외
|
||||||
|
/// - 임계값 (worldY >= playerY+1.5) 또는 작은 공중 발판 (가로≤8 + 위·아래 빈) 분류
|
||||||
|
/// - SetColliderType(Sprite) 강제
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GameOptimizer
|
public static class GameOptimizer
|
||||||
{
|
{
|
||||||
|
|
@ -16,24 +27,16 @@ namespace Platformer.Mechanics
|
||||||
QualitySettings.vSyncCount = 0;
|
QualitySettings.vSyncCount = 0;
|
||||||
Time.fixedDeltaTime = 1f / 60f;
|
Time.fixedDeltaTime = 1f / 60f;
|
||||||
|
|
||||||
// BT5-Dev #34 — Layer Matrix 영역 = Player(13) ↔ Enemy(14)만 OFF. JumpThrough Layer 8 영역 폐기.
|
// Layer Matrix: Player(13) ↔ Enemy(14) 충돌 OFF.
|
||||||
// OneWay = PlatformEffector2D 영역 표준 패턴 활용 (Layer Matrix 폐기)
|
|
||||||
Physics2D.IgnoreLayerCollision(13, 14, true);
|
Physics2D.IgnoreLayerCollision(13, 14, true);
|
||||||
Debug.Log($"[BT34-LayerSep] Player(13) ↔ Enemy(14) collision OFF (Layer 8 영역 폐기·PlatformEffector2D 영역 활용)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// BT5-Dev #27 — PD 제안: Layer 8(JumpThrough) + Raycast 동적 충돌.
|
|
||||||
/// PlatformEffector2D 폐기. 모든 일반 BoxCollider2D를 Layer 8로 변환 → 기본 통과 + Player 발 Raycast 시점만 충돌 활성.
|
|
||||||
/// 제외: Tilemap·Player·Enemy·DeathZone·VictoryZone·TokenInstance·AttackHitbox·Trigger Collider.
|
|
||||||
/// </summary>
|
|
||||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||||
static void SetupJumpThroughPlatforms()
|
static void SetupJumpThroughPlatforms()
|
||||||
{
|
{
|
||||||
// BT5-Dev #46 — PD 제안 채택: Level Tilemap = Layer 0 (일반 지면·벽 영구 충돌) / Foreground Tilemap = Layer 16 (공중 발판 Drop-Through·Tile m_ColliderType=Sprite 런타임 강제)
|
// 1. Level Tilemap = Layer 0 보존. 그 외 비-trigger Collider2D = Layer 16 강제 (Drop-Through).
|
||||||
int applied = 0, excluded = 0, levelKept = 0;
|
int applied = 0, excluded = 0, levelKept = 0;
|
||||||
var allColliders = Object.FindObjectsByType<Collider2D>(FindObjectsSortMode.None);
|
var allColliders = Object.FindObjectsByType<Collider2D>(FindObjectsSortMode.None);
|
||||||
var appliedNames = new System.Collections.Generic.List<string>();
|
|
||||||
foreach (var c in allColliders)
|
foreach (var c in allColliders)
|
||||||
{
|
{
|
||||||
if (c == null) continue;
|
if (c == null) continue;
|
||||||
|
|
@ -49,10 +52,9 @@ namespace Platformer.Mechanics
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT46 — Level Tilemap (TilemapCollider2D + name='Level') = Layer 0 (일반 지면·벽 영구 충돌)
|
|
||||||
if (c.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>() != null && c.gameObject.name == "Level")
|
if (c.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>() != null && c.gameObject.name == "Level")
|
||||||
{
|
{
|
||||||
if (c.gameObject.layer == 16) c.gameObject.layer = 0; // 잔존 복원
|
if (c.gameObject.layer == 16) c.gameObject.layer = 0;
|
||||||
var lvlEffector = c.GetComponent<PlatformEffector2D>();
|
var lvlEffector = c.GetComponent<PlatformEffector2D>();
|
||||||
if (lvlEffector != null) Object.Destroy(lvlEffector);
|
if (lvlEffector != null) Object.Destroy(lvlEffector);
|
||||||
c.usedByEffector = false;
|
c.usedByEffector = false;
|
||||||
|
|
@ -65,15 +67,9 @@ namespace Platformer.Mechanics
|
||||||
c.usedByEffector = false;
|
c.usedByEffector = false;
|
||||||
c.gameObject.layer = 16;
|
c.gameObject.layer = 16;
|
||||||
applied++;
|
applied++;
|
||||||
if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}({c.GetType().Name})");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT66 — PD 결정 R2 (2026-05-08): 자동 분류 결과 = 별도 GameObject (AutoForeground).
|
// 2. PD Foreground = 가림막 시각만 (TilemapCollider2D 제거 → 충돌 X).
|
||||||
// PD Foreground GameObject = PD 직접 그린 가림막 시각만 (TilemapCollider 제거).
|
|
||||||
// AutoForeground GameObject (신규·Grid 자식) = 본 PM 자동 분류 발판 + TilemapCollider + Layer 16 + Drop-Through.
|
|
||||||
// 결과: PD 시각 의도 (가림막 영역) 분리 + 자동 분류 발판 영역 별도 + Drop-Through 패턴 작동.
|
|
||||||
|
|
||||||
// 1. PD Foreground = 가림막 시각만. 기존 TilemapCollider2D 제거 (충돌 X).
|
|
||||||
var pdForeground = GameObject.Find("Foreground");
|
var pdForeground = GameObject.Find("Foreground");
|
||||||
if (pdForeground != null)
|
if (pdForeground != null)
|
||||||
{
|
{
|
||||||
|
|
@ -81,7 +77,8 @@ namespace Platformer.Mechanics
|
||||||
if (pdFgTc != null) Object.Destroy(pdFgTc);
|
if (pdFgTc != null) Object.Destroy(pdFgTc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. AutoForeground GameObject 신규 생성 (Grid 자식) — 자동 분류 발판 전용.
|
// 3. AutoForeground GameObject (Grid 자식·신규) — 자동 분류 발판 전용.
|
||||||
|
// transform.localPosition = PD Foreground/Level과 동기화 (시각 위치 정합).
|
||||||
GameObject gridGo = (pdForeground != null && pdForeground.transform.parent != null)
|
GameObject gridGo = (pdForeground != null && pdForeground.transform.parent != null)
|
||||||
? pdForeground.transform.parent.gameObject
|
? pdForeground.transform.parent.gameObject
|
||||||
: GameObject.Find("Grid");
|
: GameObject.Find("Grid");
|
||||||
|
|
@ -96,9 +93,6 @@ namespace Platformer.Mechanics
|
||||||
if (autoFg != null)
|
if (autoFg != null)
|
||||||
{
|
{
|
||||||
autoFg.layer = 16;
|
autoFg.layer = 16;
|
||||||
// BT67 — PD 보고 (2026-05-08): "발판의 위치가 1만큼 y로 올라갔는데 왜 그런거지?"
|
|
||||||
// 원인: AutoForeground 신규 생성 시 transform default (0,0,0) ↔ PD가 Level/Foreground를 y=-1로 직접 변경
|
|
||||||
// 정정: 매 Play 시점 PD Foreground(또는 Level) localPosition와 동기화
|
|
||||||
var refGo = pdForeground != null ? pdForeground : GameObject.Find("Level");
|
var refGo = pdForeground != null ? pdForeground : GameObject.Find("Level");
|
||||||
if (refGo != null) autoFg.transform.localPosition = refGo.transform.localPosition;
|
if (refGo != null) autoFg.transform.localPosition = refGo.transform.localPosition;
|
||||||
fgTilemap = autoFg.GetComponent<UnityEngine.Tilemaps.Tilemap>();
|
fgTilemap = autoFg.GetComponent<UnityEngine.Tilemaps.Tilemap>();
|
||||||
|
|
@ -109,10 +103,9 @@ namespace Platformer.Mechanics
|
||||||
if (fgTc == null) fgTc = autoFg.AddComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
|
if (fgTc == null) fgTc = autoFg.AddComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT48 — Level → Foreground 자동 분류 강화. 분류 조건 2종 결합:
|
// 4. Level → AutoForeground 자동 분류:
|
||||||
// (a) 임계값 위 (worldY >= playerY + 1.5) = 공중 = 무조건 Foreground (BT47 호환)
|
// - colliderType=None (배경) 제외 / 이름 prefix "TileGround" (지면·벽) 제외
|
||||||
// (b) 임계값 아래여도 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 8 tile 이하 = 작은 공중 발판
|
// - 임계값 위 OR 작은 공중 발판 = Foreground 이동 + Sprite 강제
|
||||||
// → 일반 지면(통상 10+ tile 가로) 잘못 분류 방지 + 첨부 이미지 같은 작은 발판 자동 분류
|
|
||||||
var levelGo = GameObject.Find("Level");
|
var levelGo = GameObject.Find("Level");
|
||||||
if (levelGo != null && fgTilemap != null)
|
if (levelGo != null && fgTilemap != null)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +114,7 @@ namespace Platformer.Mechanics
|
||||||
if (levelTilemap != null && player != null)
|
if (levelTilemap != null && player != null)
|
||||||
{
|
{
|
||||||
float playerY = player.transform.position.y;
|
float playerY = player.transform.position.y;
|
||||||
float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 (BT47 호환)
|
float airThresholdY = playerY + 1.5f;
|
||||||
const int MAX_PLATFORM_WIDTH = 8;
|
const int MAX_PLATFORM_WIDTH = 8;
|
||||||
var bounds = levelTilemap.cellBounds;
|
var bounds = levelTilemap.cellBounds;
|
||||||
int movedHigh = 0, movedSmall = 0;
|
int movedHigh = 0, movedSmall = 0;
|
||||||
|
|
@ -132,13 +125,8 @@ namespace Platformer.Mechanics
|
||||||
var pos = new Vector3Int(x, y, 0);
|
var pos = new Vector3Int(x, y, 0);
|
||||||
if (!levelTilemap.HasTile(pos)) continue;
|
if (!levelTilemap.HasTile(pos)) continue;
|
||||||
|
|
||||||
// BT63 — Tile asset의 m_ColliderType=None = 배경 의도 (tree·plant·fence·house) = 자동 분류 제외
|
|
||||||
// 결과: 나무·plant·fence·house Tile은 Level 잔존·자체 None Collider로 자연 통과.
|
|
||||||
var tileAsset = levelTilemap.GetTile<UnityEngine.Tilemaps.Tile>(pos);
|
var tileAsset = levelTilemap.GetTile<UnityEngine.Tilemaps.Tile>(pos);
|
||||||
if (tileAsset != null && tileAsset.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None) continue;
|
if (tileAsset != null && tileAsset.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None) continue;
|
||||||
|
|
||||||
// BT68 — TileGround* (지면·벽 의도) 자동 분류 제외 (PD 보고 2026-05-08: "대각선 점프로 벽 통과")
|
|
||||||
// 결과: TileGround·TileGroundDark·TileGroundTop Tile은 Level 잔존·Layer 0 영구 충돌·통과 X.
|
|
||||||
string nm = tileAsset != null ? tileAsset.name : string.Empty;
|
string nm = tileAsset != null ? tileAsset.name : string.Empty;
|
||||||
if (nm.StartsWith("TileGround")) continue;
|
if (nm.StartsWith("TileGround")) continue;
|
||||||
|
|
||||||
|
|
@ -146,6 +134,7 @@ namespace Platformer.Mechanics
|
||||||
bool aboveThreshold = worldPos.y >= airThresholdY;
|
bool aboveThreshold = worldPos.y >= airThresholdY;
|
||||||
bool isSmallAir = !aboveThreshold && IsSmallAirPlatform(levelTilemap, pos, MAX_PLATFORM_WIDTH);
|
bool isSmallAir = !aboveThreshold && IsSmallAirPlatform(levelTilemap, pos, MAX_PLATFORM_WIDTH);
|
||||||
if (!aboveThreshold && !isSmallAir) continue;
|
if (!aboveThreshold && !isSmallAir) continue;
|
||||||
|
|
||||||
var tile = levelTilemap.GetTile(pos);
|
var tile = levelTilemap.GetTile(pos);
|
||||||
fgTilemap.SetTile(pos, tile);
|
fgTilemap.SetTile(pos, tile);
|
||||||
fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite);
|
fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite);
|
||||||
|
|
@ -157,17 +146,14 @@ namespace Platformer.Mechanics
|
||||||
if (fgTc != null) fgTc.ProcessTilemapChanges();
|
if (fgTc != null) fgTc.ProcessTilemapChanges();
|
||||||
var lvlTc = levelGo.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
|
var lvlTc = levelGo.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
|
||||||
if (lvlTc != null) lvlTc.ProcessTilemapChanges();
|
if (lvlTc != null) lvlTc.ProcessTilemapChanges();
|
||||||
Debug.Log($"[BT48-MoveTiles] moved={movedHigh + movedSmall} (high={movedHigh} thresholdY={airThresholdY:F2} / smallAir={movedSmall} maxWidth={MAX_PLATFORM_WIDTH})");
|
Debug.Log($"[GameOptimizer] AutoForeground moved={movedHigh + movedSmall} (high={movedHigh} small={movedSmall} threshold={airThresholdY:F2}) / Layer16 applied={applied} levelKept0={levelKept} excluded={excluded}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($"[BT48-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}");
|
|
||||||
Debug.Log($"[BT48-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// BT48 — 작은 공중 발판 판별. 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 maxWidth 이하.
|
/// 작은 공중 발판 판별: 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 maxWidth 이하.
|
||||||
/// 일반 지면(통상 10+ tile 가로) 잘못 분류 방지.
|
/// 일반 지면(10+ tile 가로) 잘못 분류 방지.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static bool IsSmallAirPlatform(UnityEngine.Tilemaps.Tilemap tm, Vector3Int pos, int maxWidth)
|
static bool IsSmallAirPlatform(UnityEngine.Tilemaps.Tilemap tm, Vector3Int pos, int maxWidth)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,7 @@ namespace Platformer.Mechanics
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// BT68 — X·Y 분리 처리 (PD 보고 2026-05-08: "전진 점프 시 앞 막혀도 위로 점프 가능 의무"):
|
// 공중 hit X·Y 분리: X 이동 hit (앞 벽) = velocity.x만 0 (점프 속도 보존) / Y 이동 hit (천장) = X·Y 모두 cap
|
||||||
// X 이동 시점 hit (앞 벽) → velocity.x만 0, velocity.y 보존 (점프 속도 유지)
|
|
||||||
// Y 이동 시점 hit (천장) → velocity.x·y 모두 cap (기존 동작)
|
|
||||||
velocity.x = 0;
|
velocity.x = 0;
|
||||||
if (yMovement) velocity.y = Mathf.Min(velocity.y, 0);
|
if (yMovement) velocity.y = Mathf.Min(velocity.y, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,14 @@ namespace Platformer.Mechanics
|
||||||
public JumpState jumpState = JumpState.Grounded;
|
public JumpState jumpState = JumpState.Grounded;
|
||||||
private bool stopJump;
|
private bool stopJump;
|
||||||
|
|
||||||
// BT69 — Down + Jump Drop-Through (PD 명시 2026-05-08): Down 누른 상태에서 점프 시 발판 통과 + 점프 모션
|
// Drop-Through (Down + Jump) — 발판 위에서 Down 유지 + 점프 시 발판 통과 + 점프 모션 + 자연 낙하
|
||||||
private float dropThroughTimer = 0f; // 활성 시간 동안 Layer 16 mask 강제 OFF
|
private float dropThroughTimer = 0f;
|
||||||
private const float DROP_THROUGH_DURATION = 0.3f; // Drop-Through 활성 지속 시간 (초)
|
private const float DROP_THROUGH_DURATION = 0.3f;
|
||||||
private bool dropThroughJump = false; // 본 frame Drop-Through 점프 발동 여부 (velocity.y 처리 분기)
|
private bool dropThroughJump = false;
|
||||||
|
|
||||||
// BT72 — 점프 ascending 통과 일관성 (PD 질문 2026-05-08): 정점 영역 jitter 차단
|
// Jump Ascent — 점프 ascending·정점 영역 mask 강제 OFF 보장 (정점 jitter 차단)
|
||||||
private float jumpAscentTimer = 0f;
|
private float jumpAscentTimer = 0f;
|
||||||
private const float JUMP_ASCENT_DURATION = 0.4f; // 점프 시작 후 mask OFF 보장 시간 (정점 영역 jitter 차단)
|
private const float JUMP_ASCENT_DURATION = 0.4f;
|
||||||
/*internal new*/ public Collider2D collider2d;
|
/*internal new*/ public Collider2D collider2d;
|
||||||
/*internal new*/ public AudioSource audioSource;
|
/*internal new*/ public AudioSource audioSource;
|
||||||
public Health health;
|
public Health health;
|
||||||
|
|
@ -88,14 +88,14 @@ namespace Platformer.Mechanics
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
if (animator == null) animator = GetComponentInChildren<Animator>();
|
if (animator == null) animator = GetComponentInChildren<Animator>();
|
||||||
|
|
||||||
// PD 지시 2026-05-07 — 동반 컴포넌트 자동 부착 (Inspector 부착 불요)
|
// 동반 컴포넌트 자동 부착 (Inspector 부착 불요)
|
||||||
if (GetComponent<PlayerInvulnerabilityFlash>() == null) gameObject.AddComponent<PlayerInvulnerabilityFlash>();
|
if (GetComponent<PlayerInvulnerabilityFlash>() == null) gameObject.AddComponent<PlayerInvulnerabilityFlash>();
|
||||||
if (GetComponent<Platformer.UI.ResurrectPromptUI>() == null) gameObject.AddComponent<Platformer.UI.ResurrectPromptUI>();
|
if (GetComponent<Platformer.UI.ResurrectPromptUI>() == null) gameObject.AddComponent<Platformer.UI.ResurrectPromptUI>();
|
||||||
// BT5-Dev #34 — PlatformDropThrough 폐기 (PlatformEffector2D 표준 패턴 활용)
|
// 구 PlatformDropThrough 컴포넌트 자동 제거 (Drop-Through는 ContactFilter mask 동적 갱신으로 처리)
|
||||||
var oldDrop = GetComponent<PlatformDropThrough>();
|
var oldDrop = GetComponent<PlatformDropThrough>();
|
||||||
if (oldDrop != null) Destroy(oldDrop);
|
if (oldDrop != null) Destroy(oldDrop);
|
||||||
|
|
||||||
// PD 지시 2026-05-07 — 사망 시 입력 차단 / 부활 시 입력 복원
|
// 사망 시 입력 차단 / 부활 시 입력 복원
|
||||||
if (health != null)
|
if (health != null)
|
||||||
{
|
{
|
||||||
health.OnDeathEvent += OnHealthDeath;
|
health.OnDeathEvent += OnHealthDeath;
|
||||||
|
|
@ -121,15 +121,6 @@ namespace Platformer.Mechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT5-Dev #30 — 발판 GameObject 영역 식별 진단 (PD 영역 영역 영역 부딪힘 시 Console 출력)
|
|
||||||
void OnCollisionEnter2D(Collision2D col)
|
|
||||||
{
|
|
||||||
if (col.gameObject == null) return;
|
|
||||||
int layer = col.gameObject.layer;
|
|
||||||
string name = col.gameObject.name;
|
|
||||||
Debug.Log($"[BT30-Collide] name='{name}' layer={layer} (8=JumpThrough, 0=Default)");
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnHealthDeath()
|
void OnHealthDeath()
|
||||||
{
|
{
|
||||||
controlEnabled = false;
|
controlEnabled = false;
|
||||||
|
|
@ -149,9 +140,7 @@ namespace Platformer.Mechanics
|
||||||
move.x = moveInput.x;
|
move.x = moveInput.x;
|
||||||
if (jumpState == JumpState.Grounded && m_JumpAction.WasPressedThisFrame())
|
if (jumpState == JumpState.Grounded && m_JumpAction.WasPressedThisFrame())
|
||||||
{
|
{
|
||||||
// BT69 — Down + Jump = Drop-Through (PD 명시 2026-05-08)
|
// Down + Jump 발판 위 = Drop-Through 발동 / 지면 위 = 일반 점프
|
||||||
// BT70 — 발판(Layer 16) 위 검증 추가 (PD 보고 2026-05-08: 지면 위 Down + Jump = 점프 X 버그)
|
|
||||||
// 발판 위만 Drop-Through 발동·지면 위 = 일반 점프
|
|
||||||
bool downHeld = moveInput.y < -0.5f;
|
bool downHeld = moveInput.y < -0.5f;
|
||||||
bool onJumpThroughPlatform = false;
|
bool onJumpThroughPlatform = false;
|
||||||
if (downHeld && collider2d != null)
|
if (downHeld && collider2d != null)
|
||||||
|
|
@ -180,19 +169,18 @@ namespace Platformer.Mechanics
|
||||||
move.x = 0;
|
move.x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT69 — Drop-Through Timer 감소 (Layer 16 mask 강제 OFF 지속 시간)
|
// Drop-Through·Jump Ascent Timer 감소 (mask 강제 OFF 지속 시간)
|
||||||
if (dropThroughTimer > 0f) dropThroughTimer -= Time.deltaTime;
|
if (dropThroughTimer > 0f) dropThroughTimer -= Time.deltaTime;
|
||||||
// BT72 — Jump Ascent Timer 감소 (점프 ascending 통과 일관성)
|
|
||||||
if (jumpAscentTimer > 0f) jumpAscentTimer -= Time.deltaTime;
|
if (jumpAscentTimer > 0f) jumpAscentTimer -= Time.deltaTime;
|
||||||
UpdateJumpState();
|
UpdateJumpState();
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
// PD 지시 2026-05-07 — 낙사 시 복귀할 안전 위치 추적
|
// 낙사 시 복귀할 안전 위치 추적
|
||||||
if (IsGrounded) LastGroundedPosition = transform.position;
|
if (IsGrounded) LastGroundedPosition = transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT5-Dev #40 — 개발팀장 진단: KinematicObject.Start() contactFilter 캐싱 우회
|
// Drop-Through Layer (Foreground·AutoForeground GameObject Layer 16).
|
||||||
// Physics2D.IgnoreLayerCollision은 raycast contactFilter 영역 무관. SetLayerMask 직접 갱신 의무.
|
// KinematicObject body.Cast의 contactFilter는 Start() 시점 캐싱되므로 Drop-Through는 SetLayerMask 동적 갱신으로 처리.
|
||||||
const int JUMP_THROUGH_LAYER = 16;
|
const int JUMP_THROUGH_LAYER = 16;
|
||||||
|
|
||||||
void UpdateJumpState()
|
void UpdateJumpState()
|
||||||
|
|
@ -204,9 +192,9 @@ namespace Platformer.Mechanics
|
||||||
jumpState = JumpState.Jumping;
|
jumpState = JumpState.Jumping;
|
||||||
jump = true;
|
jump = true;
|
||||||
stopJump = false;
|
stopJump = false;
|
||||||
// BT72 — 점프 ascending 통과 일관성: Drop-Through 점프(velocity.y<0)는 Timer 활성 X (이미 dropThroughTimer 영역)
|
// 일반 점프만 ascending 통과 보장 Timer 활성 (Drop-Through는 dropThroughTimer로 처리)
|
||||||
if (!dropThroughJump) jumpAscentTimer = JUMP_ASCENT_DURATION;
|
if (!dropThroughJump) jumpAscentTimer = JUMP_ASCENT_DURATION;
|
||||||
// BT41 — PrepareToJump frame 영역 즉시 contactFilter Layer 16 mask OFF (다음 ComputeVelocity 영역 velocity.y 적용 영역 영역 frame 영역 발판 영역 충돌 차단)
|
// PrepareToJump frame 즉시 mask OFF — 다음 frame ComputeVelocity의 velocity.y 적용 직전 발판 충돌 차단
|
||||||
{
|
{
|
||||||
int baseMaskJump = Physics2D.GetLayerCollisionMask(gameObject.layer);
|
int baseMaskJump = Physics2D.GetLayerCollisionMask(gameObject.layer);
|
||||||
contactFilter.SetLayerMask(baseMaskJump & ~(1 << JUMP_THROUGH_LAYER));
|
contactFilter.SetLayerMask(baseMaskJump & ~(1 << JUMP_THROUGH_LAYER));
|
||||||
|
|
@ -232,17 +220,18 @@ namespace Platformer.Mechanics
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT40 — Drop-Through: velocity.y > 0(상승) 영역 Layer 16 mask 비활성, 그 외 활성
|
|
||||||
UpdateContactFilterForDropThrough();
|
UpdateContactFilterForDropThrough();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Drop-Through 패턴: ascending·정점·Drop-Through Timer 활성 시 Layer 16 mask OFF (통과).
|
||||||
|
/// 그 외 = footHit 3점 Raycast (Layer 16) — 발판 가장자리 안정 검출.
|
||||||
|
/// 점프·낙하 중 정점 영역 + 수평 입력 + 발판 가장자리 일시 검출 = 밀림 상태 → 강제 Drop-Through 발동.
|
||||||
|
/// </summary>
|
||||||
void UpdateContactFilterForDropThrough()
|
void UpdateContactFilterForDropThrough()
|
||||||
{
|
{
|
||||||
int baseMask = Physics2D.GetLayerCollisionMask(gameObject.layer);
|
int baseMask = Physics2D.GetLayerCollisionMask(gameObject.layer);
|
||||||
|
|
||||||
// BT5-Dev #43 — IsGrounded 영역 폐기 (frame 0 미설정 → 떨어짐). footHit 단독 + 점프 영역 OFF 강제
|
|
||||||
// BT69 — Drop-Through Timer 활성 시 Layer 16 mask 강제 OFF (Down + Jump 입력 발판 통과)
|
|
||||||
// BT72 — Jump Ascent Timer 활성 시 mask 강제 OFF (정점 영역 jitter 차단·점프 통과 일관성)
|
|
||||||
bool isJumpingThrough = jumpState == JumpState.Jumping
|
bool isJumpingThrough = jumpState == JumpState.Jumping
|
||||||
|| (jumpState == JumpState.InFlight && velocity.y > 0.01f)
|
|| (jumpState == JumpState.InFlight && velocity.y > 0.01f)
|
||||||
|| dropThroughTimer > 0f
|
|| dropThroughTimer > 0f
|
||||||
|
|
@ -251,9 +240,7 @@ namespace Platformer.Mechanics
|
||||||
bool standingOnPlatform = false;
|
bool standingOnPlatform = false;
|
||||||
if (collider2d != null && !isJumpingThrough)
|
if (collider2d != null && !isJumpingThrough)
|
||||||
{
|
{
|
||||||
// BT73 — footHit Raycast 3점 (좌·중·우) (PD 보고 2026-05-08: 발판 가장자리 jitter)
|
// footHit Raycast 3점 (좌·중·우) — 가장자리 jitter 차단
|
||||||
// 단일 중앙 Raycast 시 가장자리 영역 검출 X·검출 O frame 교차 → 밀려남
|
|
||||||
// 좌·중·우 3점 어느 하나라도 검출 시 standingOnPlatform=true → 안정
|
|
||||||
float footY = collider2d.bounds.min.y + 0.02f;
|
float footY = collider2d.bounds.min.y + 0.02f;
|
||||||
float boundsLeft = collider2d.bounds.min.x + 0.02f;
|
float boundsLeft = collider2d.bounds.min.x + 0.02f;
|
||||||
float boundsCenter = collider2d.bounds.center.x;
|
float boundsCenter = collider2d.bounds.center.x;
|
||||||
|
|
@ -264,9 +251,7 @@ namespace Platformer.Mechanics
|
||||||
RaycastHit2D footHitR = Physics2D.Raycast(new Vector2(boundsRight, footY), Vector2.down, 0.1f, jumpThroughMask);
|
RaycastHit2D footHitR = Physics2D.Raycast(new Vector2(boundsRight, footY), Vector2.down, 0.1f, jumpThroughMask);
|
||||||
standingOnPlatform = footHitC.collider != null || footHitL.collider != null || footHitR.collider != null;
|
standingOnPlatform = footHitC.collider != null || footHitL.collider != null || footHitR.collider != null;
|
||||||
|
|
||||||
// BT74 — 밀림 상태 강제 Drop-Through (PD 권고 2026-05-08: "한번이라도 밀리면 아래로 강제로 떨구어야")
|
// 밀림 상태 강제 Drop-Through (점프·낙하 중 정점 + 수평 입력 + 발판 가장자리 일시 검출)
|
||||||
// 점프·낙하 중 정점 영역(velocity.y > -1.5) + 수평 입력 + 발판 가장자리 일시 검출 = 밀림 상태
|
|
||||||
// → dropThroughTimer 강제 활성 + standingOnPlatform=false 즉시 해제
|
|
||||||
bool inAir = jumpState == JumpState.Jumping || jumpState == JumpState.InFlight;
|
bool inAir = jumpState == JumpState.Jumping || jumpState == JumpState.InFlight;
|
||||||
bool nearApex = velocity.y > -1.5f;
|
bool nearApex = velocity.y > -1.5f;
|
||||||
bool horizontalIntent = Mathf.Abs(move.x) > 0.1f;
|
bool horizontalIntent = Mathf.Abs(move.x) > 0.1f;
|
||||||
|
|
@ -277,7 +262,6 @@ namespace Platformer.Mechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// standingOnPlatform=true → Layer 16 ON (착지·서있는 영역 영역 X) / 그 외 → Layer 16 OFF (통과)
|
|
||||||
int mask = standingOnPlatform ? baseMask : (baseMask & ~(1 << JUMP_THROUGH_LAYER));
|
int mask = standingOnPlatform ? baseMask : (baseMask & ~(1 << JUMP_THROUGH_LAYER));
|
||||||
contactFilter.SetLayerMask(mask);
|
contactFilter.SetLayerMask(mask);
|
||||||
contactFilter.useLayerMask = true;
|
contactFilter.useLayerMask = true;
|
||||||
|
|
@ -287,13 +271,10 @@ namespace Platformer.Mechanics
|
||||||
{
|
{
|
||||||
if (jump && IsGrounded)
|
if (jump && IsGrounded)
|
||||||
{
|
{
|
||||||
// BT69 — Drop-Through 점프 분기: Down + Jump 입력 시 위로 점프 X (gravity로 떨어짐 + 점프 모션만 유지)
|
// Drop-Through 점프: 위로 점프 X (음수 velocity.y로 즉시 낙하 시작 + 점프 애니메이션만 유지)
|
||||||
// BT71 — velocity.y = 0 → 음수(-0.5) 정정 (PD 보고 2026-05-08: Drop-Through 후 점프키 X 버그)
|
|
||||||
// 원인: velocity.y=0 시 IsGrounded=true 잔존 → jumpState=Jumping 영구 → 점프 입력 무시
|
|
||||||
// 정정: 즉시 떨어짐 → IsGrounded=false → Jumping→InFlight→착지→Grounded 정상 사이클
|
|
||||||
if (dropThroughJump)
|
if (dropThroughJump)
|
||||||
{
|
{
|
||||||
velocity.y = -0.5f; // 즉시 낙하 시작 — 발판 통과 + IsGrounded=false 확보
|
velocity.y = -0.5f;
|
||||||
dropThroughJump = false;
|
dropThroughJump = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue