npc寻路逻辑完成
This commit is contained in:
parent
609550513f
commit
d46b3e56de
@ -553,7 +553,7 @@ public class test : MonoBehaviour
|
|||||||
}
|
}
|
||||||
if (npcData.Type == 2)//npcÒƶ¯
|
if (npcData.Type == 2)//npcÒƶ¯
|
||||||
{
|
{
|
||||||
Vector3 v = new Vector3(-float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()), float.Parse(npcData.Z.ToString()));
|
Vector3 v = new Vector3(float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()) + 0.5f, float.Parse(npcData.Z.ToString()));
|
||||||
foreach (RecuseNpc item in NPCController.instance.npcsList)
|
foreach (RecuseNpc item in NPCController.instance.npcsList)
|
||||||
{
|
{
|
||||||
if (npcData.UserId == item.npcId)
|
if (npcData.UserId == item.npcId)
|
||||||
|
@ -111,7 +111,7 @@ NavMeshSettings:
|
|||||||
agentClimb: 0.4
|
agentClimb: 0.4
|
||||||
ledgeDropHeight: 0
|
ledgeDropHeight: 0
|
||||||
maxJumpAcrossDistance: 0
|
maxJumpAcrossDistance: 0
|
||||||
minRegionArea: 2
|
minRegionArea: 0.1
|
||||||
manualCellSize: 0
|
manualCellSize: 0
|
||||||
cellSize: 0.016666668
|
cellSize: 0.016666668
|
||||||
manualTileSize: 0
|
manualTileSize: 0
|
||||||
|
@ -61,7 +61,7 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
if (other.tag == "Player")
|
if (other.tag == "Player")
|
||||||
recusebtn.gameObject.SetActive(true);
|
recusebtn.gameObject.SetActive(true);
|
||||||
if (statebool) return;
|
if (statebool) return;
|
||||||
other.GetComponent<CharacterInturn>().cha = this.gameObject;
|
// other.GetComponent<CharacterInturn>().cha = this.gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerExit(Collider other)
|
private void OnTriggerExit(Collider other)
|
||||||
@ -172,24 +172,24 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
|
|
||||||
public void Run(Vector3 target)
|
public void Run(Vector3 target)
|
||||||
{
|
{
|
||||||
|
if (!navMeshAgent.enabled)
|
||||||
|
{
|
||||||
|
Debug.LogError("NavMeshAgent 未启用!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (navMeshAgent.isStopped)
|
if (navMeshAgent.isStopped)
|
||||||
{
|
{
|
||||||
navMeshAgent.isStopped = false; // 取消停止状态
|
navMeshAgent.isStopped = false; // 取消停止状态
|
||||||
}
|
}
|
||||||
Debug.Log("进入奔跑");
|
|
||||||
|
Debug.Log("进入奔跑状态");
|
||||||
if (movebool)
|
if (movebool)
|
||||||
{
|
{
|
||||||
// 确保目标点在 NavMesh 上
|
NavMeshPath path = new NavMeshPath();
|
||||||
NavMeshHit hit;
|
navMeshAgent.SetDestination(target);
|
||||||
if (NavMesh.SamplePosition(target, out hit, 1.0f, NavMesh.AllAreas))
|
|
||||||
{
|
SetAni(1); // 设置奔跑动画
|
||||||
navMeshAgent.SetDestination(hit.position);
|
|
||||||
SetAni(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"目标点 {target} 不在导航网格上");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user