지하 생성 및 터널 구조 개선
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TunnelTraveler : MonoBehaviour
|
||||
{
|
||||
@@ -8,58 +7,33 @@ public class TunnelTraveler : MonoBehaviour
|
||||
private bool _isTraveling;
|
||||
public bool IsTraveling => _isTraveling;
|
||||
|
||||
public void StartTravel(TunnelNode start)
|
||||
public void StartTravel(Vector3 targetPos, bool isBottom)
|
||||
{
|
||||
if (_isTraveling) return;
|
||||
|
||||
// [디버그 1] 상호작용한 노드의 연결 상태 확인
|
||||
Debug.Log($"<color=white>[Travel] 시작 노드: {start.name} | 위: {(start.aboveNode != null)} | 아래: {(start.belowNode != null)}</color>");
|
||||
|
||||
List<Vector3> path = new List<Vector3>();
|
||||
|
||||
// 이동 방향 결정 (아래가 있으면 아래로, 없으면 위로)
|
||||
bool goDown = start.belowNode != null;
|
||||
TunnelNode curr = goDown ? start.belowNode : start.aboveNode;
|
||||
|
||||
while (curr != null)
|
||||
{
|
||||
path.Add(curr.transform.position);
|
||||
curr = goDown ? curr.belowNode : curr.aboveNode;
|
||||
}
|
||||
|
||||
// [디버그 2] 최종 경로 개수 확인
|
||||
Debug.Log($"<color=yellow>[Travel] 생성된 경로 포인트 개수: {path.Count}</color>");
|
||||
|
||||
if (path.Count > 0)
|
||||
{
|
||||
StartCoroutine(Travel(path));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("<color=red>[Travel] 이동할 경로가 없습니다! 노드 연결을 확인하세요.</color>");
|
||||
}
|
||||
// 하단 노드가 목적지라면 캐릭터 중심 좌표를 고려해 약간 더 아래(바닥)로 설정
|
||||
Vector3 finalDestination = isBottom ? targetPos + Vector3.down * 0.5f : targetPos;
|
||||
StartCoroutine(TravelRoutine(finalDestination));
|
||||
}
|
||||
|
||||
private IEnumerator Travel(List<Vector3> path)
|
||||
private IEnumerator TravelRoutine(Vector3 destination)
|
||||
{
|
||||
Debug.Log("<color=green>[Travel] 코루틴 이동 시작!</color>");
|
||||
_isTraveling = true;
|
||||
var cc = GetComponent<CharacterController>();
|
||||
if (cc) cc.enabled = false;
|
||||
|
||||
foreach (var point in path)
|
||||
// X, Z는 유지한 채 Y축 중심으로 이동
|
||||
float halfHeight = cc ? cc.height / 2f : 0f;
|
||||
Vector3 target = new Vector3(destination.x, destination.y - halfHeight, destination.z);
|
||||
|
||||
while (Vector3.Distance(transform.position, target) > 0.05f)
|
||||
{
|
||||
Vector3 target = new Vector3(point.x, point.y - (cc ? cc.height / 2 : 0), point.z);
|
||||
while (Vector3.Distance(transform.position, target) > 0.1f)
|
||||
{
|
||||
transform.position = Vector3.MoveTowards(transform.position, target, travelSpeed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
transform.position = target;
|
||||
transform.position = Vector3.MoveTowards(transform.position, target, travelSpeed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.position = target;
|
||||
if (cc) cc.enabled = true;
|
||||
_isTraveling = false;
|
||||
Debug.Log("<color=green>[Travel] 이동 완료!</color>");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user