From bc7818a1c581c3d2cbab562fb55fb29cc32d9ecb Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 18 Jul 2024 20:04:54 +0900 Subject: [PATCH] [Upstream] fix: Fix raycast shortcuts (@Sarofc) Raycast is performed in 2d and it might report reaching the given position even if the Y coordinate is different than the target. Therefore, it is necessary to check what poly is actually hit by raycast before taking a shortcut. - https://github.com/recast4j/recast4j/issues/196 - https://github.com/recast4j/recast4j/pull/197 - https://github.com/ikpil/DotRecast/issues/72 --- CHANGELOG.md | 2 +- src/DotRecast.Detour/DtNavMeshQuery.cs | 6 +++--- src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9216655..cf89ff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Nothing ### Fixed -- Nothing +- Fix raycast shortcuts ([@Sarofc](https://github.com/Sarofc)) [#72](https://github.com/ikpil/DotRecast/issues/72) ### Changed - Changed data structure of 'neis' from List to byte[] for optimized memory usage and improved access speed in `DtLayerMonotoneRegion` diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 4d186ba..0a83738 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -980,7 +980,7 @@ namespace DotRecast.Detour DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef); if (rayStatus.Succeeded()) { - foundShortCut = rayHit.t >= 1.0f; + foundShortCut = rayHit.t >= 1.0f && rayHit.path[^1] == neighbourRef; if (foundShortCut) { shortcut = new List(rayHit.path); @@ -1296,7 +1296,7 @@ namespace DotRecast.Detour DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef); if (status.Succeeded()) { - foundShortCut = rayHit.t >= 1.0f; + foundShortCut = rayHit.t >= 1.0f && rayHit.path[^1] == neighbourRef; if (foundShortCut) { shortcut = new List(rayHit.path); @@ -3143,7 +3143,7 @@ namespace DotRecast.Detour int maxSegments) { segmentCount = 0; - + DtStatus status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly); if (status.Failed()) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 2375bf6..150a1d7 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -272,7 +272,7 @@ namespace DotRecast.Recast.Toolset.Tools // results ... polys = path; - if (t > 1) + if (t >= 1) { // No hit hitPos = endPos;