[Realm Rush] Pathfinding Progress on my version

In my version of Realm Rush (named Aliens&Castles in a spark of originality) I’m taking the BFS pathfinding one step further and implementing a “danger level” for the different paths depending on how many defensive towers are laid out along them. As the following gif shows for the green path, enemies will always try to look for the least dangerous, but still shortest, path. This forces players to strategize their tower placement.

Apart from regular enemies, I want to implement enemies with weapons that will do the complete opposite: calculate the most dangerous paths to exclusively destroy towers.

So far it’s looking nice!



Whoa :exploding_head: You made this? It looks incredible

1 Like

Thanks, but I’m afraid the credit should go to Kenney Assets (it’s his tower defense pack) and also @garypettie for much of the code provided in the course. I’m just tweaking things here and there and “putting the puzzle together”, so to say :P.

On another note, here comes a new update. I had performance problems with enemies calculating paths upon respawn. I assigned the EnemyPathing script to the enemy prefabs, now all possible paths are calculated upon game loading (a max of 5 paths per spawning point and target tile) and assigned to the script that moves the enemies, and on enemy respawn I just loop through those paths in the enemy moving script to calculate the danger level of each and assign the least dangerous. Now there are no hiccups during play but a much longer initial loading is required.

Here is a gif with 2 enemies per spawning point and how their paths differ when they spawn again when towers are placed:

Aliens&Castles Wave

Great work @OuterGazer.
It sounds like you’ve gone and upgraded the basic BFS algorithm from the course and converted it to Dijkstra by adding some danger weighting to the paths.
You probably shouldn’t be seeing any performance issues at this kind of scale, so there may just be a few inefficiencies here and there that you can fine tune.
You may find this article from Red Blog Games helpful Introduction to the A* Algorithm

Keep up the great work and share a link to your game once everything is working :slight_smile:

1 Like

Thanks for the link Gary! I’ll chek it out. I’ll let you guys know about the finished version, of course. Although that may be in a couple of weeks still.

The performance issue comes because I customized the BFS, most probably in a not so efficient way. Instead of finishing pathfinding when the target coordinates are reached, I call the CreatePath() method recursively. I have some bools in the crossings set up, so that the chosen path out of a crossroad gets blocked for subsequent pathfindings. This forces the recursion to find increasingly longer paths to the target tile. I set it so that after 5 different paths are found it quits the recursion, so the repetition of these many loops was causing hiccups.

1 Like

Time for a new update! I’ve spent the last couple of days designing the towers and enemies with their behaviours and here is another gif showcasing them. Players will have acces to balistas, cannon and catapult towers. Enemies will have non-violent and violent enemies. Red non-violent will target the red castle at the end, white non-violent will target the purple castle more in the middle. Both will always look for the shortest, and less dangerous, path available. Violent alien enemies are balistas, cannons and missile launchers. Those will pendle between their spawn points and the target point of the purple castle back and forth always through the most dangerous path.

Hope fully this will strike a balance in the placement of towers and procure some fun gameplay. Only menus, tutorial windows, balancing and polishing left.

Aliens&Castles Preview