From e307d640488903169f2b8f8758afccae1111e182 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 16 Aug 2024 02:02:16 +0200 Subject: [PATCH] Recast: always check edge direction Should always be checked, linking edges that face the same direction causes the ai to perform unnecessary jumps and sometimes even causes it to clip into geometry. --- src/naveditor/Editor.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/naveditor/Editor.cpp b/src/naveditor/Editor.cpp index 4f6b466c..fc0041dc 100644 --- a/src/naveditor/Editor.cpp +++ b/src/naveditor/Editor.cpp @@ -752,28 +752,24 @@ void Editor::connectTileTraverseLinks(dtMeshTile* const baseTile, const bool lin rdVsub(baseEdgeDir, basePolyEpos, basePolySpos); rdVsub(landEdgeDir, landPolyEpos, landPolySpos); - // todo(amos): use height difference instead of slope angles. + const float dotProduct = rdVdot(baseEdgeDir, landEdgeDir); + + // Edges facing the same direction should not be linked. + // Doing so causes links to go through from underneath + // geometry. E.g. we have an HVAC on a roof, and we try + // to link our roof poly edge facing north to the edge + // of the poly on the HVAC also facing north, the link + // will go through the HVAC and thus cause the NPC to + // jump through it. + // Another case where this is necessary is when having + // a land edge that connects with the base edge, this + // prevents the algorithm from establishing a parallel + // traverse link. + if (dotProduct > 0) + continue; + + // todo(amos): should we use height difference instead of slope angles? const float slopeAngle = rdMathFabsf(rdCalcSlopeAngle(basePolyEdgeMid, landPolyEdgeMid)); - - if (slopeAngle < TRAVERSE_OVERLAP_SLOPE_THRESHOLD) - { - const float dotProduct = rdVdot(baseEdgeDir, landEdgeDir); - - // Edges facing the same direction should not be linked. - // Doing so causes links to go through from underneath - // geometry. E.g. we have an HVAC on a roof, and we try - // to link our roof poly edge facing north to the edge - // of the poly on the HVAC also facing north, the link - // will go through the HVAC and thus cause the NPC to - // jump through it. - // Another case where this is necessary is when having - // a land edge that connects with the base edge, this - // prevents the algorithm from establishing a parallel - // traverse link. - if (dotProduct > 0) - continue; - } - const bool samePolyGroup = basePoly->groupId == landPoly->groupId; const TraverseType_e traverseType = GetBestTraverseType(slopeAngle, quantDist, samePolyGroup); @@ -791,7 +787,7 @@ void Editor::connectTileTraverseLinks(dtMeshTile* const baseTile, const bool lin const float heightDiff = higherEdgeMid[2] - lowerEdgeMid[2]; const float maxAngle = rdCalcMaxLOSAngle(walkableRadius, m_cellHeight); - const float offsetAmount = rdCalcLedgeSpanOffsetAmount(walkableRadius/*+4.0f*/, slopeAngle, maxAngle); + const float offsetAmount = rdCalcLedgeSpanOffsetAmount(walkableRadius, slopeAngle, maxAngle); if (!traverseLinkInLOS(m_geom, lowerEdgeMid, higherEdgeMid, lowerEdgeDir, higherEdgeDir, offsetAmount)) continue;