转自: http://wiki.ceeger.com/script/unityengine/classes/navmesh/navmesh.sampleposition
转自: http://answers.unity3d.com/questions/475066/how-to-get-a-random-point-on-navmesh.html
I generated a random point with in a unit sphere and multiplied it by the max distance I wanted my agents to walk:
Vector3 randomDirection = Random.insideUnitSphere * walkRadius;
I then added my agents current position to this vector and used the NavMesh.SamplePosition function to find the close position on the NavMesh:
randomDirection += transform.position;
NavMeshHit hit;
NavMesh.SamplePosition(randomDirection, out hit, walkRadius, 1);
Vector3 finalPosition = hit.position;I then used final postion as the destination for my agent.
Hope this helps!
本文介绍了一种在Unity中为导航网格(NavMesh)生成随机有效位置的方法。该方法首先生成一个单位球体内的随机方向,并将其乘以允许的最大行走距离。然后将此方向向量加到代理当前的位置上,并使用NavMesh.SamplePosition函数来找到最近的有效路径点。
4624

被折叠的 条评论
为什么被折叠?



