I’m new to Unity and I’m playing around with pathfinding algorithms. I’ve written my own Dijkstra algorithm, which returns a List of ‘Vector3’ objects with all the nodes that conform the shortest path.
In the game there is an enemy tank and the player’s tank. The idea is that the enemy tank should follow the player’s tank wherever it goes, and find its way around obstacles if there are any.
Now, the way I have coded this is that there are two main possibilities.
- The enemy tank sees the enemy tank and therefore goes straight towards it,
- or it doesn’t see it and the Dijkstra algorithm gets called.
The green path would be the path obtained through the Dijkstra algorithm. The problem is that, as soon as the enemy tank sees the player’s tank again, this path gets overriden by a straight line towards the player’s tank. The result is quite sloppy, as the enemy tank will collide against edges and that’ll slow it down.
Any ideas to solve this? Thanks a lot!!!