0 votes


After implementing enemy pathfinding with AStar2D, we added diagonal lines for 8-way instead of 4-way.

However, at certain object positions (randomly creating objects), it showed different values than I expected.

expected path


The AStar2D implementation was grid-based using tilemap. The game is top-down, and the implementation of AStar2D has been made using any examples floating around the Internet.

thank you.

( I used the A* simulator from https://qiao.github.io/PathFinding.js/visual )

Godot version 3.3.3
in Engine by (77 points)

1 Answer

+1 vote
Best answer

in the result Image because it's 8 ways and it checks for the neighbors [ top-left, top-right , bottom-left, bottom-right] and if they are empty then the object should move to them without checking if the left or up tiles are free, my advice is to use the 4 ways for path finding then simplify the path to have 8 diagonal movement

by (272 points)
selected by

you just need an algorithm like the pixel perfect algorithm to simplify the path after finding it

Thank you!

So, I made it in 4 directions first, and when it was diagonal, I put 0 in x and y, respectively, and after checking, if both are empty, I moved it diagonally.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.