- Home /
How do I go about adding basic pathfinding to my enemy?
I have a top down 2D game, and I need the enemy to go from its current position to a different one (I know the location of where it needs to go). Currently, I rotate the enemy to face the new position, and then make it go forward. However, if there's a collider in the way then of course it will just bump into it and get stuck. How do I get it to go around colliders and add some basic pathfinding? Any advice is greatly appreciated!
Answer by I_Am_Err00r · Jul 22, 2019 at 04:21 PM
A* is an algorithm designed to get from point a to b the quickest while considering obstacles in the way, lucky for us this algorithm is available in tools like this one and all the complicated code is taken care of and we just plug in the objects and variables, even luckier there is a free version of it on the website that can calculate shortest distance and avoid obstacles in 2D; for a top down game like you are talking about it works great.
I have even found a video on youtube that goes through the entire process of downloading it and importing from the website to building a quick graph that detects obstacles: https://www.youtube.com/watch?v=4T7KHysRw84
Thanks a lot! This seems perfect for me, especially since pathfinding isn't a part of game design I find especially fun :p.
Your answer
Follow this Question
Related Questions
2D Pathfinding Top Down 0 Answers
Gameobject not moving unless starting at 0 transform 0 Answers
2D AI, Aim at player - even when jumping? 1 Answer
Why is my gameObject falling so slow? 1 Answer
Having trouble with A* pathfinding 1 Answer