BT5-Dev #48: 작은 공중 발판 자동 분류 강화 (위·아래 빈 공간 + 가로 ≤8 tile)

BT47 단일 임계값(playerY+1.5) 의존 한계: 첨부 이미지 같은 낮은 위치 발판 누락.

BT48 분류 조건 2종 결합:
- (a) 임계값 위 = 무조건 공중 (BT47 호환)
- (b) 임계값 아래여도 위·아래 인접 Tile 모두 빈 공간 + 가로 연속 길이 ≤8 tile = 작은 공중 발판
  → 일반 지면(통상 10+ tile) 잘못 분류 방지 + PD 의도 발판 자동 포함

표준 One-Way Platform / Drop-Through 패턴 정합 (Layer 16 + ContactFilter2D 동적 mask).

8 tile 임계값 = 추정 proxy (일반 platformer 지면 10+ tile 가정·실측 미확증).
PD 시각 검증 후 의도와 다른 발판 분류 시 임계값 조정 또는 알고리즘 재설계 후속.

PD Editor Refresh+Play 시 Console [BT48-MoveTiles] high=N smallAir=M 출력으로 분류 결과 검증 가능.
본 PM 직접 Editor.log read 의무 (PD 시각 검증 결과 보고 직후).
This commit is contained in:
깃 관리자 2026-05-07 21:27:11 +09:00
parent 1024e089c7
commit b84c236761
1 changed files with 39 additions and 9 deletions

View File

@ -80,7 +80,10 @@ namespace Platformer.Mechanics
fgTilemap = foreground.GetComponent<UnityEngine.Tilemaps.Tilemap>();
}
// BT47 — Level Tilemap의 공중 Tile (Player 시작 Y + 1.5 이상 영역) 영역 → Foreground 영역 자동 이동
// BT48 — Level → Foreground 자동 분류 강화. 분류 조건 2종 결합:
// (a) 임계값 위 (worldY >= playerY + 1.5) = 공중 = 무조건 Foreground (BT47 호환)
// (b) 임계값 아래여도 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 8 tile 이하 = 작은 공중 발판
// → 일반 지면(통상 10+ tile 가로) 잘못 분류 방지 + 첨부 이미지 같은 작은 발판 자동 분류
var levelGo = GameObject.Find("Level");
if (levelGo != null && fgTilemap != null)
{
@ -89,9 +92,10 @@ namespace Platformer.Mechanics
if (levelTilemap != null && player != null)
{
float playerY = player.transform.position.y;
float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 발판 영역
float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 (BT47 호환)
const int MAX_PLATFORM_WIDTH = 8;
var bounds = levelTilemap.cellBounds;
int moved = 0;
int movedHigh = 0, movedSmall = 0;
for (int x = bounds.xMin; x <= bounds.xMax; x++)
{
for (int y = bounds.yMin; y <= bounds.yMax; y++)
@ -99,24 +103,50 @@ namespace Platformer.Mechanics
var pos = new Vector3Int(x, y, 0);
if (!levelTilemap.HasTile(pos)) continue;
Vector3 worldPos = levelTilemap.CellToWorld(pos);
if (worldPos.y < airThresholdY) continue; // 지면·벽 영역 그대로
// 공중 영역 Tile → Foreground 영역 영역 이동
bool aboveThreshold = worldPos.y >= airThresholdY;
bool isSmallAir = !aboveThreshold && IsSmallAirPlatform(levelTilemap, pos, MAX_PLATFORM_WIDTH);
if (!aboveThreshold && !isSmallAir) continue;
var tile = levelTilemap.GetTile(pos);
fgTilemap.SetTile(pos, tile);
fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite);
levelTilemap.SetTile(pos, null);
moved++;
if (aboveThreshold) movedHigh++;
else movedSmall++;
}
}
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($"[BT48-MoveTiles] moved={movedHigh + movedSmall} (high={movedHigh} thresholdY={airThresholdY:F2} / smallAir={movedSmall} maxWidth={MAX_PLATFORM_WIDTH})");
}
}
Debug.Log($"[BT47-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT47-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
Debug.Log($"[BT48-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}");
Debug.Log($"[BT48-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]");
}
/// <summary>
/// BT48 — 작은 공중 발판 판별. 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 maxWidth 이하.
/// 일반 지면(통상 10+ tile 가로) 잘못 분류 방지.
/// </summary>
static bool IsSmallAirPlatform(UnityEngine.Tilemaps.Tilemap tm, Vector3Int pos, int maxWidth)
{
if (tm.HasTile(pos + Vector3Int.up)) return false;
if (tm.HasTile(pos + Vector3Int.down)) return false;
int width = 1;
for (int dx = 1; dx <= maxWidth; dx++)
{
if (!tm.HasTile(pos + new Vector3Int(dx, 0, 0))) break;
width++;
if (width > maxWidth) return false;
}
for (int dx = 1; dx <= maxWidth; dx++)
{
if (!tm.HasTile(pos + new Vector3Int(-dx, 0, 0))) break;
width++;
if (width > maxWidth) return false;
}
return width <= maxWidth;
}
}
}