BT5-Dev #47: Level Tilemap 공중 Tile 영역 자동 영역 Foreground 이동 (Y > Player 시작 +1.5)

PD 보고: 공중 발판 통과 X 여전 ([BT30-Collide] name='Level' layer=0)
PD 진단: prefab 영역 영역 영역

본 PM 자인:
- Level Tilemap = 일반 지면 + 공중 발판 통합 = 단일 GameObject 모든 Tile 동일 동작 = 분리 X
- 공중 발판 부딪힘 = Level Tilemap 일부 Tile

정정 (런타임 자동 분리):
- Player 시작 Y + 1.5 위 Tile = 공중 발판 영역 → Foreground Tilemap 영역 자동 이동
- Level Tilemap의 해당 Tile 영역 제거
- Foreground Tile m_ColliderType=Sprite 강제
- 양 Tilemap ProcessTilemapChanges 영역 영역 영역

동작:
- Level Tilemap (Layer 0) = 일반 지면·벽 (영구 충돌)
- Foreground Tilemap (Layer 16 + Sprite Collider) = 공중 발판 (Drop-Through)
- Player 점프 → 공중 발판 통과 / 벽 영역 막힘
- Player 걷기 → 공중 발판 옆 통과 / 일반 지면 영역 영역
This commit is contained in:
깃 관리자 2026-05-07 18:42:03 +09:00
parent 06c6d5b3c7
commit 1024e089c7
1 changed files with 32 additions and 15 deletions

View File

@ -68,38 +68,55 @@ namespace Platformer.Mechanics
if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}({c.GetType().Name})");
}
// BT46 — Foreground GameObject TilemapCollider2D + Layer 16 + 모든 Tile m_ColliderType=Sprite 런타임 강제
// BT47 — Foreground TilemapCollider2D + Layer 16 (ColliderType Sprite 강제는 Tile 이동 후 한 번에 처리)
var foreground = GameObject.Find("Foreground");
UnityEngine.Tilemaps.Tilemap fgTilemap = null;
UnityEngine.Tilemaps.TilemapCollider2D fgTc = null;
if (foreground != null)
{
var fgTc = foreground.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
fgTc = foreground.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
if (fgTc == null) fgTc = foreground.AddComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
foreground.layer = 16;
fgTilemap = foreground.GetComponent<UnityEngine.Tilemaps.Tilemap>();
}
var fgTilemap = foreground.GetComponent<UnityEngine.Tilemaps.Tilemap>();
if (fgTilemap != null)
// BT47 — Level Tilemap의 공중 Tile (Player 시작 Y + 1.5 이상 영역) 영역 → Foreground 영역 자동 이동
var levelGo = GameObject.Find("Level");
if (levelGo != null && fgTilemap != null)
{
var levelTilemap = levelGo.GetComponent<UnityEngine.Tilemaps.Tilemap>();
var player = Object.FindFirstObjectByType<PlayerController>();
if (levelTilemap != null && player != null)
{
var bounds = fgTilemap.cellBounds;
int forced = 0;
float playerY = player.transform.position.y;
float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 발판 영역
var bounds = levelTilemap.cellBounds;
int moved = 0;
for (int x = bounds.xMin; x <= bounds.xMax; x++)
{
for (int y = bounds.yMin; y <= bounds.yMax; y++)
{
var pos = new Vector3Int(x, y, 0);
if (fgTilemap.HasTile(pos))
{
fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite);
forced++;
}
if (!levelTilemap.HasTile(pos)) continue;
Vector3 worldPos = levelTilemap.CellToWorld(pos);
if (worldPos.y < airThresholdY) continue; // 지면·벽 영역 그대로
// 공중 영역 Tile → Foreground 영역 영역 이동
var tile = levelTilemap.GetTile(pos);
fgTilemap.SetTile(pos, tile);
fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite);
levelTilemap.SetTile(pos, null);
moved++;
}
}
fgTc.ProcessTilemapChanges();
Debug.Log($"[BT46-Foreground] TilemapCollider2D + Layer 16 + ColliderType=Sprite forced on {forced} tiles");
if (fgTc != null) fgTc.ProcessTilemapChanges();
var lvlTc = levelGo.GetComponent<UnityEngine.Tilemaps.TilemapCollider2D>();
if (lvlTc != null) lvlTc.ProcessTilemapChanges();
Debug.Log($"[BT47-MoveTiles] moved={moved} air tiles from Level (worldY>={airThresholdY:F2}) to Foreground");
}
}
Debug.Log($"[BT46-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT46-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
Debug.Log($"[BT47-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT47-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
}
}
}