BT5-Dev #109: footPos cell 영역 정정·BT104 Raycast 재배치 폐기
PD 질문 (2026-05-08): "몬스터가 왜 움직지 않는거지?" 진단: - BT107 footPos.y = bounds.min.y - 0.1f = Enemy 발 영역 cell (cell y=2) - 그러나 실제 발판 영역 = cell y=1 (발 아래 영역) - → HasTile(_, 2) X → startTm = null → return 0f - → patrol 거리 0 → 이동 X 정정 (BT109): 1. footPos.y: bounds.min.y - 0.1 → bounds.min.y - 0.5 (발판 cell 영역 정확) 2. Debug.Log 추가 — dir·footPos.y·startTm·startCell 진단 3. BT104 Raycast 재배치 영역 폐기 (Raycast 영역 부정확·BT107 Tilemap cell 기반 측정으로 일원화) 효과: - footPos = 발판 cell 영역 (cell y=1) → HasTile 정합 → startTm·startCell 영역 정합 - 측정 정확 → patrolMaxRange/_maxRightRange/_maxLeftRange 정확 - patrol 정상 작동
This commit is contained in:
parent
5dbde11a48
commit
3dfc466a9e
|
|
@ -105,37 +105,8 @@ namespace Platformer.Mechanics
|
|||
// BT104 — 시작 위치 발판 검증·자동 재배치 (PD가 PD Foreground·빈 영역 배치 시 가까운 발판 영역으로 이동)
|
||||
void Start()
|
||||
{
|
||||
if (_collider != null)
|
||||
{
|
||||
Vector2 footHere = new Vector2(_collider.bounds.center.x, _collider.bounds.min.y + 0.05f);
|
||||
RaycastHit2D groundUnder = Physics2D.Raycast(footHere, Vector2.down, cliffCheckDepth, groundLayerMask);
|
||||
if (groundUnder.collider == null)
|
||||
{
|
||||
// 시작 위치 발판 X — 가까운 좌·우 발판 자동 검색
|
||||
for (float d = 0.5f; d <= 50f; d += 0.5f)
|
||||
{
|
||||
Vector2 rightProbe = new Vector2(_startX + d, footHere.y);
|
||||
if (Physics2D.Raycast(rightProbe, Vector2.down, cliffCheckDepth, groundLayerMask).collider != null)
|
||||
{
|
||||
_startX += d;
|
||||
Vector3 newPos = new Vector3(_startX, transform.position.y, transform.position.z);
|
||||
transform.position = newPos;
|
||||
if (_body != null) _body.position = newPos;
|
||||
break;
|
||||
}
|
||||
Vector2 leftProbe = new Vector2(_startX - d, footHere.y);
|
||||
if (Physics2D.Raycast(leftProbe, Vector2.down, cliffCheckDepth, groundLayerMask).collider != null)
|
||||
{
|
||||
_startX -= d;
|
||||
Vector3 newPos = new Vector3(_startX, transform.position.y, transform.position.z);
|
||||
transform.position = newPos;
|
||||
if (_body != null) _body.position = newPos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_startY = transform.position.y; // 재배치 후 _startY 갱신
|
||||
// BT109 — Raycast 영역 폐기 (BT104 영역 부정확). Tilemap cell 기반 시작 위치 발판 검증.
|
||||
_startY = transform.position.y;
|
||||
|
||||
_maxRightRange = MeasureSafeWalkDistance(1f);
|
||||
_maxLeftRange = MeasureSafeWalkDistance(-1f);
|
||||
|
|
@ -188,8 +159,10 @@ namespace Platformer.Mechanics
|
|||
}
|
||||
if (groundTilemaps.Count == 0) return 0f;
|
||||
|
||||
// 시작 cell = Enemy 발 아래 cell
|
||||
Vector3 footPos = new Vector3(_startX, _collider.bounds.min.y - 0.1f, 0f);
|
||||
// BT109 — footPos 영역 정정 (PD 보고 2026-05-08: 이동 X)
|
||||
// bounds.min.y - 0.1f = Enemy 발 영역 cell → 발판 cell X
|
||||
// → bounds.min.y - 0.5f = 발판 cell 영역 정확 검사
|
||||
Vector3 footPos = new Vector3(_startX, _collider.bounds.min.y - 0.5f, 0f);
|
||||
UnityEngine.Tilemaps.Tilemap startTm = null;
|
||||
Vector3Int startCell = Vector3Int.zero;
|
||||
foreach (var tm in groundTilemaps)
|
||||
|
|
@ -202,6 +175,7 @@ namespace Platformer.Mechanics
|
|||
break;
|
||||
}
|
||||
}
|
||||
Debug.Log($"[Enemy@{name}] dir={dir} footPos.y={footPos.y:F2} startTm={(startTm!=null?startTm.name:"NULL")} startCell={startCell}");
|
||||
if (startTm == null) return 0f;
|
||||
|
||||
// 좌·우 연속 Tile 영역 끝 영역 검색
|
||||
|
|
|
|||
Loading…
Reference in New Issue