static bool getSteerTarget(Detour.dtNavMeshQuery navQuery, float[] startPos, float[] endPos, float minTargetDist, dtPolyRef[] path, int pathSize, float[] steerPos, ref byte steerPosFlag, ref dtPolyRef steerPosRef) { // Find steer target. const int MAX_STEER_POINTS = 3; float[] steerPath = new float[MAX_STEER_POINTS*3]; byte[] steerPathFlags = new byte[MAX_STEER_POINTS]; dtPolyRef[] steerPathPolys = new dtPolyRef[MAX_STEER_POINTS]; int nsteerPath = 0; navQuery.findStraightPath(startPos, endPos, path, pathSize, steerPath, steerPathFlags, steerPathPolys, ref nsteerPath, MAX_STEER_POINTS, 0); if (nsteerPath == 0) return false; // Find vertex far enough to steer to. int ns = 0; while (ns < nsteerPath) { // Stop at Off-Mesh link or when point is further than slop away. if ((steerPathFlags[ns] & (byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 || !inRange(steerPath, ns*3, startPos, 0, minTargetDist, 1000.0f)) break; ns++; } // Failed to find good point to steer to. if (ns >= nsteerPath) return false; Detour.dtVcopy(steerPos, 0, steerPath,ns*3); steerPos[1] = startPos[1]; steerPosFlag = steerPathFlags[ns]; steerPosRef = steerPathPolys[ns]; return true; }
public static StraightPath ComputeStraightPath(Detour.dtNavMeshQuery navQuery, float[] startPos, float[] endPos) { //m_ComputedPathType = PathType.Straight; StraightPath path = new StraightPath(); float[] extents = new float[3]; for (int i=0;i<3;++i){ extents[i] = 10.0f; } dtPolyRef startRef = 0; dtPolyRef endRef = 0; float[] startPt = new float[3]; float[] endPt = new float[3]; Detour.dtQueryFilter filter = new Detour.dtQueryFilter(); navQuery.findNearestPoly( startPos, extents, filter, ref startRef, ref startPt ); navQuery.findNearestPoly( endPos, extents, filter, ref endRef, ref endPt ); int pathCount = -1; navQuery.findPath(startRef, endRef, startPt, endPt, filter, path.m_RawPathPolys, ref pathCount, StraightPath.MAX_POLYS); path.m_RawPathLength = pathCount; if (pathCount > 0) { // In case of partial path, make sure the end point is clamped to the last polygon. float[] epos = new float[3]; Detour.dtVcopy(epos, endPt); if (path.m_RawPathPolys[pathCount - 1] != endRef) { bool posOverPoly = false; navQuery.closestPointOnPoly(path.m_RawPathPolys[pathCount - 1], endPt, epos, ref posOverPoly); } navQuery.findStraightPath(startPt, endPt, path.m_RawPathPolys, pathCount, path.m_straightPath, path.m_straightPathFlags, path.m_straightPathPolys, ref path.m_straightPathCount, StraightPath.MAX_POLYS, path.m_straightPathOptions); } return path; }