Switching to A* Pathfinding: Deterrence - Video Devlog 6

The sixth weekly devlog of Deterrence. This week I delve into handling enemy units, scaling heads up display for all resolutions, and implementing A* pathfinding in Unity.

A tower defense mixed with real-time strategy where you repel attacking sentient AI robots until they give up.


Handling Enemy Units

The easiest and most optimal way in my opinion for player units to check for enemy units in their surroundings is for player units to have a static list of enemy units to check distances with. When an enemy is created, it will add itself to the list and vice versa. If the enemy is in range for a unit, then the enemy is added to the units local 'enemies in range' list. Further layers will be added to prioritize what enemies to attack first.

Player unit movement will take in an additonal variable storing the command given by the player. With attack move, the unit should pause it's path to engage enemies in range before finishing the path. And with a regular move command, the unit should finish it's path before engaging any enemies in range.

A* Pathfinding

The A* pathfinding tutorial by Sebastian Lague can be found on YouTube. There were a few modifications I've made to the script to fix some issues I've found with A* pathfinding. I noticed how the A* pathfinding would fail if the target node was an unwalkable node, so I made a quick method to search for a nearby walkable node to find a path to. This way if a player commands units to move towards an unwalkable cliff, the units will still move to the general area.

Another problem with the A* pathfinding is islands. If the start or end points are surrounded by unwalkable nodes, then the path will fail. Determining if either one is on an island using a flood fill method can be expensive on the CPU depending on how large the island is.

One can simply try to solve this problem by finding islands when the grid is created at the start of the game, but that still won't find islands created by the player building walls. If anyone has any solutions, let me know in the comments below!

Sebastian Lague A* Pathfinding Tutorial -

Latest Jobs


Playa Vista, Los Angeles, CA, USA
Senior Physics Gameplay Engineer - Treyarch

High Moon Studios

Carlsbad, CA, USA
VFX Artist - High Moon Studios

Anne Arundel Community College

Arnold, MD, USA
Instructor/Assistant Professor, Game Art

Treyarch Vancouver

Vancouver, BC, Canada
Producer - Treyarch Vancouver
More Jobs   


Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter


Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Follow us


Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more