Unity寻路 终点偏差

问题遇到的现象和发生背景

Unity用设定寻路目标的时候,利用这个API naveMeshAgent.SetDestination,设置完毕后,navemeshagent的destination和设置的有偏差?

问题相关代码,请勿粘贴截图
Vector3[] geoPeopleDestroyVector ={
            new Vector3(75.88168f, 11.5f,126.2816f),
            new Vector3(85.16019f, 11.5f,176.5286f),
            new Vector3(111.43f, 11.5f,176.5286f),
            new Vector3(141.26f , 1.5f,183.9f),
            new Vector3(136.66f , 1.5f,183.9f),
            new Vector3(130.48f , 1.5f,183.9f),
            new Vector3(125.9f, 1.5f,183.9f),
            
            new Vector3(141.26f , 1.5f,163.56f),
            new Vector3(136.66f , 1.5f,163.38f),
            new Vector3(130.48f , 1.5f,163.38f),
            new Vector3(125.9f, 1.5f,163.38f)
        };
        nav = GetComponent();
        rand = Random.Range(0, geoPeopleDestroyVector.Length);
        nav.SetDestination(geoPeopleDestroyVector[rand]);
        targrt = nav.destination;
        targetpos = geoPeopleDestroyVector[rand];  //targrt和targetpos理论上来说应该是一样的,但是打印出来却有偏差
运行结果及报错内容

img

img

img

list里面的多个终点,有的没有偏差,有的有偏差,不知道为什么?

我的解答思路和尝试过的方法

我尝试过将子物体与父物体的中心点,对齐,但是都没有效果

我想要达到的结果

我希望设置的终点和实际运行的重点不要有偏差!

你可以这样,到达时重新设定位置,Unity寻路系统我用的不多,我一直在用A*寻路,我觉得有偏差是正常的,接近时位置应该是模糊位置

是否可以截图NavMeshAgent的物体,从你描述的问题猜测有几种可能
1.代码设置问题,切换点是通过什么来判断到达位置。
2.加速度设置问题。
3.

img

你这个写法有点问题,第17行,nav.SetDestination(geoPeopleDestroyVector[rand]); SetDestination():设置或更新目的地,从而触发新路径的计算。
第18行,targrt = nav.destination; destination:获取或尝试以世界空间单位设置代理的目的地。

SetDestination()用法:https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.SetDestination.html

destination的用法:https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent-destination.html


你现在这么写,很有可能当SetDestination()移动到一半时,targrt就被赋值了。即当SetDestination未执行完成时,nav.destination的值就不是目标点。