Help with Dijkstra and following a path

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.

alt text

Now, the way I have coded this is that there are two main possibilities.

  1. The enemy tank sees the enemy tank and therefore goes straight towards it,
  2. 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!!!

The simplest way i could think of immediately is increasing the distance between the nodes such that the slope of the line is changed, giving you more free space. The best distance to calculate the nodes position is the longest width the tank collider could possibly have( like the diagonal length).