Pathfinding.NavMeshGraph.ClosestPointOnNode C# (CSharp) Method

ClosestPointOnNode() public static method

public static ClosestPointOnNode ( TriangleMeshNode node, Int3 vertices, Vector3 pos ) : Vector3
node TriangleMeshNode
vertices Int3
pos UnityEngine.Vector3
return UnityEngine.Vector3
		public static Vector3 ClosestPointOnNode (TriangleMeshNode node, Int3[] vertices, Vector3 pos) {
			return Polygon.ClosestPointOnTriangle ((Vector3)vertices[node.v0],(Vector3)vertices[node.v1],(Vector3)vertices[node.v2],pos);
		}
		

Usage Example

Ejemplo n.º 1
0
        public static NNInfo GetNearest(NavMeshGraph graph, GraphNode[] nodes, Vector3 position, NNConstraint constraint, bool accurateNearestNode)
        {
            if (nodes == null || nodes.Length == 0)
            {
                Debug.LogError("NavGraph hasn't been generated yet or does not contain any nodes");
                return(default(NNInfo));
            }
            if (constraint == null)
            {
                constraint = NNConstraint.None;
            }
            Int3[] vertices = graph.vertices;
            if (graph.bbTree == null)
            {
                return(NavMeshGraph.GetNearestForce(graph, graph, position, constraint, accurateNearestNode));
            }
            float  num    = (graph.bbTree.Size.width + graph.bbTree.Size.height) * 0.5f * 0.02f;
            NNInfo result = graph.bbTree.QueryCircle(position, num, constraint);

            if (result.node == null)
            {
                for (int i = 1; i <= 8; i++)
                {
                    result = graph.bbTree.QueryCircle(position, (float)(i * i) * num, constraint);
                    if (result.node != null || (float)((i - 1) * (i - 1)) * num > AstarPath.active.maxNearestNodeDistance * 2f)
                    {
                        break;
                    }
                }
            }
            if (result.node != null)
            {
                result.clampedPosition = NavMeshGraph.ClosestPointOnNode(result.node as TriangleMeshNode, vertices, position);
            }
            if (result.constrainedNode != null)
            {
                if (constraint.constrainDistance && ((Vector3)result.constrainedNode.position - position).sqrMagnitude > AstarPath.active.maxNearestNodeDistanceSqr)
                {
                    result.constrainedNode = null;
                }
                else
                {
                    result.constClampedPosition = NavMeshGraph.ClosestPointOnNode(result.constrainedNode as TriangleMeshNode, vertices, position);
                }
            }
            return(result);
        }
All Usage Examples Of Pathfinding.NavMeshGraph::ClosestPointOnNode