diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index e3a815d..2e1d00c 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -215,7 +215,7 @@ namespace DotRecast.Detour.Crowd { if (res.Count > 1 && t > 0.99f) { - m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, m_maxPath, res); + m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, m_path.Count, m_maxPath, res); } } } @@ -241,13 +241,13 @@ namespace DotRecast.Detour.Crowd } var res = new List(); - navquery.InitSlicedFindPath(m_path[0], m_path[m_path.Count - 1], m_pos, m_target, filter, 0); + navquery.InitSlicedFindPath(m_path[0], m_path[^1], m_pos, m_target, filter, 0); navquery.UpdateSlicedFindPath(maxIterations, out var _); var status = navquery.FinalizeSlicedFindPathPartial(m_path, ref res); if (status.Succeeded() && res.Count > 0) { - m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, m_maxPath, res); + m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, m_path.Count, m_maxPath, res); return true; } @@ -316,7 +316,7 @@ namespace DotRecast.Detour.Crowd var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_path = DtPathUtils.MergeCorridorStartMoved(m_path, m_maxPath, visited); + m_path = DtPathUtils.MergeCorridorStartMoved(m_path, m_path.Count, m_maxPath, visited); // Adjust the position to stay on top of the navmesh. m_pos = result; @@ -355,10 +355,10 @@ namespace DotRecast.Detour.Crowd { // Move along navmesh and update new position. var visited = new List(); - var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, ref visited); + var status = navquery.MoveAlongSurface(m_path[^1], m_target, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_path = DtPathUtils.MergeCorridorEndMoved(m_path, m_maxPath, visited); + m_path = DtPathUtils.MergeCorridorEndMoved(m_path, m_path.Count, m_maxPath, visited); // TODO: should we do that? // Adjust the position to stay on top of the navmesh. /* diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index 1e47677..7534f29 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -141,7 +141,7 @@ namespace DotRecast.Detour return path; } - public static List MergeCorridorStartMoved(List path, int maxPath, List visited) + public static List MergeCorridorStartMoved(List path, int npath, int maxPath, List visited) { int furthestPath = -1; int furthestVisited = -1; @@ -186,7 +186,7 @@ namespace DotRecast.Detour return result; } - public static List MergeCorridorEndMoved(List path, int maxPath, List visited) + public static List MergeCorridorEndMoved(List path, int npath, int maxPath, List visited) { int furthestPath = -1; int furthestVisited = -1; @@ -223,7 +223,7 @@ namespace DotRecast.Detour return result; } - public static List MergeCorridorStartShortcut(List path, int maxPath, List visited) + public static List MergeCorridorStartShortcut(List path, int npath, int maxPath, List visited) { int furthestPath = -1; int furthestVisited = -1; diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 1e48e14..a9c9b62 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -92,7 +92,7 @@ namespace DotRecast.Recast.Toolset.Tools iterPos = result; - pathIterPolys = DtPathUtils.MergeCorridorStartMoved(pathIterPolys, MAX_POLYS, visited); + pathIterPolys = DtPathUtils.MergeCorridorStartMoved(pathIterPolys, pathIterPolys.Count, MAX_POLYS, visited); pathIterPolys = DtPathUtils.FixupShortcuts(pathIterPolys, navQuery); var status = navQuery.GetPolyHeight(pathIterPolys[0], result, out var h);