[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
This commit is contained in:
ikpil 2024-07-18 20:04:54 +09:00 committed by Ikpil
parent a87f34e738
commit bc7818a1c5
3 changed files with 5 additions and 5 deletions

View File

@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Nothing - Nothing
### Fixed ### Fixed
- Nothing - Fix raycast shortcuts ([@Sarofc](https://github.com/Sarofc)) [#72](https://github.com/ikpil/DotRecast/issues/72)
### Changed ### Changed
- Changed data structure of 'neis' from List<byte> to byte[] for optimized memory usage and improved access speed in `DtLayerMonotoneRegion` - Changed data structure of 'neis' from List<byte> to byte[] for optimized memory usage and improved access speed in `DtLayerMonotoneRegion`

View File

@ -980,7 +980,7 @@ namespace DotRecast.Detour
DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef); DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef);
if (rayStatus.Succeeded()) if (rayStatus.Succeeded())
{ {
foundShortCut = rayHit.t >= 1.0f; foundShortCut = rayHit.t >= 1.0f && rayHit.path[^1] == neighbourRef;
if (foundShortCut) if (foundShortCut)
{ {
shortcut = new List<long>(rayHit.path); shortcut = new List<long>(rayHit.path);
@ -1296,7 +1296,7 @@ namespace DotRecast.Detour
DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef); DtRaycastOptions.DT_RAYCAST_USE_COSTS, ref rayHit, grandpaRef);
if (status.Succeeded()) if (status.Succeeded())
{ {
foundShortCut = rayHit.t >= 1.0f; foundShortCut = rayHit.t >= 1.0f && rayHit.path[^1] == neighbourRef;
if (foundShortCut) if (foundShortCut)
{ {
shortcut = new List<long>(rayHit.path); shortcut = new List<long>(rayHit.path);

View File

@ -272,7 +272,7 @@ namespace DotRecast.Recast.Toolset.Tools
// results ... // results ...
polys = path; polys = path;
if (t > 1) if (t >= 1)
{ {
// No hit // No hit
hitPos = endPos; hitPos = endPos;