diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-08-02 21:36:46 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-08-02 21:36:46 +0200 |
commit | d7f07820aa9ce658df6bb0fd2691adf181a4c6fb (patch) | |
tree | 40aff7ff8798b1956e265c7d6e4c01b787fea454 /modules/navigation/nav_map.cpp | |
parent | dc05278b03851df00f4cf5e70d20764892cbe90f (diff) | |
parent | c51e2644466b96d414d4e42a9cfe283ce1162264 (diff) | |
download | redot-engine-d7f07820aa9ce658df6bb0fd2691adf181a4c6fb.tar.gz |
Merge pull request #79228 from smix8/fix_funnel_4.x
Fix pathfinding funnel adding unwanted point
Diffstat (limited to 'modules/navigation/nav_map.cpp')
-rw-r--r-- | modules/navigation/nav_map.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 745c227fe5..8b7274d673 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -431,6 +431,17 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p if (p_optimize) { // Set the apex poly/point to the end point gd::NavigationPoly *apex_poly = &navigation_polys[least_cost_id]; + + Vector3 back_pathway[2] = { apex_poly->back_navigation_edge_pathway_start, apex_poly->back_navigation_edge_pathway_end }; + const Vector3 back_edge_closest_point = Geometry3D::get_closest_point_to_segment(end_point, back_pathway); + if (end_point.is_equal_approx(back_edge_closest_point)) { + // The end point is basically on top of the last crossed edge, funneling around the corners would at best do nothing. + // At worst it would add an unwanted path point before the last point due to precision issues so skip to the next polygon. + if (apex_poly->back_navigation_poly_id != -1) { + apex_poly = &navigation_polys[apex_poly->back_navigation_poly_id]; + } + } + Vector3 apex_point = end_point; gd::NavigationPoly *left_poly = apex_poly; |