You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity 6 AI导航网格中Agent无法移动或无故卡顿问题求助

我在NavMesh上生成小兵Agent,并将其目标设置为路径点数组中的点,但遇到了问题:非垂直移动时一切正常,一旦进入垂直移动状态,小兵有时会无故卡顿。

小兵生成代码

private void CreateMinion(PlayerNumber player, UnitSO unitData)
{
    Transform[] pathPoints = GetCurrentPlayerPaths((int)player);
    Transform spawn = player == PlayerNumber.Player1 ? P1CreepsSpawn : P2CreepsSpawn;
    GameObject newMinion = Instantiate(unitPrefab, new Vector3(pathPoints[0].position.x, spawn.position.y), Quaternion.identity);
    newMinion.GetComponent<Unit>().minionAttributes = unitData;
    newMinion.GetComponent<Unit>().player = (int)player;
    newMinion.GetComponent<Unit>().playerPath = pathPoints;
    newMinion.GetComponent<NetworkObject>().Spawn(true);
}

小兵OnNetworkSpawn逻辑

agent.updateRotation = false;
agent.updateUpAxis = false;
agent.speed = minionAttributes.MoveSpeed;

if (NavMesh.SamplePosition(playerPath[pointIndex].position, out NavMeshHit hit, 0.25f, NavMesh.AllAreas))
{
    Debug.Log($"NAV HIT BABY: {hit.position}");
    NavMeshPath path = new NavMeshPath();
    bool yep = agent.CalculatePath(hit.position, path);
    Debug.Log($"Path: {path.status} ({yep})");
    agent.SetDestination(hit.position);
}

现象说明

  • 垂直移动时:用Debug.DrawLine绘制的红色路径显示异常,小兵出现卡顿
  • 非垂直移动时:路径正常,小兵移动无问题

使用的是NavMesh Plus Components,如需更多细节可补充。

内容的提问来源于stack exchange,提问作者GaLzZy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 10:25:11