BT5-Dev #38: Layer 16(JumpThrough) + 동적 IgnoreLayerCollision 토글 (PD 제안 채택)

PD 보고: 발판 통과 X 여전 (BT35 PlatformEffector2D+Composite 영역 동작 X)
PD 제안: 충돌 로직 바꿔서 해결

표준 Drop-Through 패턴:
- Tilemap·Alien Layer 16 변환 (BT38)
- 기본: Player(13) ↔ JumpThrough(16) 충돌 ON = 정상 착지
- PlayerController.Update: velocity.y > 0.05 (상승) → IgnoreLayerCollision(13, 16, true) = 모든 발판 통과
- velocity.y <= 0.05 (하강·정지) → IgnoreLayerCollision(13, 16, false) = 충돌 ON = 착지

폐기:
- PlatformEffector2D·CompositeCollider2D·Rigidbody2D Static (BT35 영역)
- Layer 8·PlatformDropThrough Raycast (BT27·BT31 영역)

동작 (PD 의도 정합):
- Player 점프 상승 → 발판 모두 통과
- Player 하강 → 발판 위 착지
- 옆·아래에서 점프 → 통과 (상승 영역 모든 Layer 16 OFF)
This commit is contained in:
깃 관리자 2026-05-07 18:07:54 +09:00
parent 2b345d929c
commit e5c5898f79
2 changed files with 17 additions and 38 deletions

View File

@ -30,9 +30,8 @@ namespace Platformer.Mechanics
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void SetupJumpThroughPlatforms()
{
// BT5-Dev #34 — Unity 표준 OneWay Platform = PlatformEffector2D + useOneWay + surfaceArc 180.
// 모든 일반 Collider(Tilemap 포함) PlatformEffector2D 적용. Layer 영역 무관 (기본 Layer 0 유지).
// 동작: 위에서 떨어지면 충돌(착지) / 옆·아래·점프 상승 시 통과
// BT5-Dev #38 — 표준 Drop-Through 패턴: Layer 16(JumpThrough) + 동적 IgnoreLayerCollision 토글
// 점프 상승 = IgnoreLayerCollision(13, 16, true) 통과 / 하강 = false 충돌 ON
int applied = 0, excluded = 0;
var allColliders = Object.FindObjectsByType<Collider2D>(FindObjectsSortMode.None);
var appliedNames = new System.Collections.Generic.List<string>();
@ -51,45 +50,20 @@ namespace Platformer.Mechanics
continue;
}
if (c.gameObject.layer == 8) c.gameObject.layer = 0;
// BT5-Dev #35 — TilemapCollider2D 영역 표준 패턴 (CompositeCollider2D + Rigidbody2D Static + PlatformEffector2D)
var tilemapCollider = c.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
if (tilemapCollider != null)
{
tilemapCollider.compositeOperation = Collider2D.CompositeOperation.Merge;
var composite = c.GetComponent<CompositeCollider2D>();
if (composite == null) composite = c.gameObject.AddComponent<CompositeCollider2D>();
var rb = c.GetComponent<Rigidbody2D>();
if (rb == null) rb = c.gameObject.AddComponent<Rigidbody2D>();
rb.bodyType = RigidbodyType2D.Static;
composite.usedByEffector = true;
var compositeEffector = c.GetComponent<PlatformEffector2D>();
if (compositeEffector == null) compositeEffector = c.gameObject.AddComponent<PlatformEffector2D>();
compositeEffector.useOneWay = true;
compositeEffector.surfaceArc = 180f;
compositeEffector.rotationalOffset = 0f;
compositeEffector.useSideFriction = false;
compositeEffector.useSideBounce = false;
applied++;
if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}(Tilemap+Composite)");
continue;
}
// 일반 Collider — PlatformEffector2D 직접 적용
c.usedByEffector = true;
// BT38 — PlatformEffector2D·CompositeCollider2D·Rigidbody2D 영역 영역 영역 폐기
var effector = c.GetComponent<PlatformEffector2D>();
if (effector == null) effector = c.gameObject.AddComponent<PlatformEffector2D>();
effector.useOneWay = true;
effector.surfaceArc = 180f;
effector.rotationalOffset = 0f;
effector.useSideFriction = false;
effector.useSideBounce = false;
if (effector != null) Object.Destroy(effector);
c.usedByEffector = false;
// Layer 16(JumpThrough) 변환
c.gameObject.layer = 16;
applied++;
if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}({c.GetType().Name})");
}
Debug.Log($"[BT35-OneWay] applied={applied} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT35-OneWay] appliedSamples=[{string.Join(", ", appliedNames)}]");
Debug.Log($"[BT38-DropThrough] applied={applied} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT38-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
// 기본 = Player(13) ↔ JumpThrough(16) 충돌 ON. PlayerController.Update에서 점프 시 동적 토글
Physics2D.IgnoreLayerCollision(13, 16, false);
}
}
}

View File

@ -155,6 +155,11 @@ namespace Platformer.Mechanics
// PD 지시 2026-05-07 — 낙사 시 복귀할 안전 위치 추적
if (IsGrounded) LastGroundedPosition = transform.position;
// BT5-Dev #38 — 표준 Drop-Through: 점프 상승(velocity.y > 0) Layer 16 통과·하강(≤0) 충돌 ON
const int JUMP_THROUGH_LAYER = 16;
bool rising = velocity.y > 0.05f;
Physics2D.IgnoreLayerCollision(13, JUMP_THROUGH_LAYER, rising);
}
void UpdateJumpState()