diff options
author | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-23 21:19:16 +0300 |
---|---|---|
committer | Yuri Rubinsky <chaosus89@gmail.com> | 2023-01-06 13:40:24 +0300 |
commit | 4a45c76737894af819d0c9f95202253d4b2570f3 (patch) | |
tree | d0573e5f9a99b996ceab5748899bf0dd1e28879b /core | |
parent | b14f7aa9f92ff44135c283a9c88dab5ef9136d64 (diff) |
Fix jumping in `AStarGrid2D` when `DIAGONAL_MODE_NEVER` is enabled
Diffstat (limited to 'core')
-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; } |