diff options
author | Yuri Rubinsky <chaosus89@gmail.com> | 2023-01-07 00:04:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 00:04:28 +0300 |
commit | 60515f62bb7825153c84c9728ad58fb6b6eb694e (patch) | |
tree | 5d2c344e38d873839240b0e304078c5765ad13cf | |
parent | 0e0557146ca535f1e9e6ba2e2e004e621a415ca1 (diff) | |
parent | 4a45c76737894af819d0c9f95202253d4b2570f3 (diff) |
Merge pull request #70485 from Chaosus/fix_astargrid_jumping
-rw-r--r-- | core/math/a_star_grid_2d.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 215e69129c..cacdde6da5 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -246,17 +246,11 @@ AStarGrid2D::Point *AStarGrid2D::_jump(Point *p_from, Point *p_to) { } } else { // DIAGONAL_MODE_NEVER if (dx != 0) { - if (!_is_walkable(to_x + dx, to_y)) { + if ((_is_walkable(to_x, to_y - 1) && !_is_walkable(to_x - dx, to_y - 1)) || (_is_walkable(to_x, to_y + 1) && !_is_walkable(to_x - dx, to_y + 1))) { return p_to; } - if (_jump(p_to, _get_point(to_x, to_y + 1)) != nullptr) { - return p_to; - } - if (_jump(p_to, _get_point(to_x, to_y - 1)) != nullptr) { - return p_to; - } - } else { - if (!_is_walkable(to_x, to_y + dy)) { + } else if (dy != 0) { + if ((_is_walkable(to_x - 1, to_y) && !_is_walkable(to_x - 1, to_y - dy)) || (_is_walkable(to_x + 1, to_y) && !_is_walkable(to_x + 1, to_y - dy))) { return p_to; } if (_jump(p_to, _get_point(to_x + 1, to_y)) != nullptr) { @@ -266,9 +260,7 @@ AStarGrid2D::Point *AStarGrid2D::_jump(Point *p_from, Point *p_to) { return p_to; } } - if (_is_walkable(to_x + dx, to_y + dy) && _is_walkable(to_x + dx, to_y) && _is_walkable(to_x, to_y + dy)) { - return _jump(p_to, _get_point(to_x + dx, to_y + dy)); - } + return _jump(p_to, _get_point(to_x + dx, to_y + dy)); } return nullptr; } |