Warfront Infinite Dev Blog #1: 3D Models and Pathfinding
About the Game
As you probably have guessed from the title, the game I’m working on is a Tower Defense type of game. At this point I’m still not sure what theme it’s going to be in, but I think I will go with military based theme. The game itself is inspired by Red Alert, Robo Defense and Kingdom Rush. For development side of things I’m using Java/Kotlin (mostly Kotlin) + OpenGL and LWJGL with the IntellJ IDEA editor.
In the last couple of weeks I’ve been learning how to make 3D models using Blender. After few days of modelling I got hang of the basics and could model few simple trees, turrets and a car which I then imported into the game “engine”. Here are few screenshots of the models that I have created during those days:
I have programmed a pathfinding management system, which uses flood-fill pathfinding algorithm to calculate where the enemies have to go. The way it works is pretty simple. You start by splitting your game map into square nodes and then generating a gradient map which will tell how far away the current node is from the target node. To do this, you firstly start at the target node, assign its value to 0, then for all the neighboring nodes increment their value by 1, or whatever number you want, as long as its a positive number. If the neighboring node is non-collidable, assign its value to something very large, like 999999.
To get the path from the start node to the current node you start at the start node, and select its neighboring node with the lowest value. Then for that selected node, do the same process until you reach node with the value of 0, which will mean that you have reached your target node.
This is how the gradient map looks in my game:
Here you can see the numbers at the center of each node which represent its value. The cars are moving towards the surrounding nodes which have the lowest values until they reach 0, that’s when they stop.
Okey, so why did I use this method instead of the famous A* algorithm? First of all. This is heck of a lot faster. Instead of always calculating a path each frame for each entity. You just generate the gradient map once, and update it every time an object is placed on the map. The drawback of this method is that all the entities can only go to a single target destination. If you want multiple target destinations, you will have to recalculate the gradient map with different target nodes.
There’s not much of a gameplay at this stage of development. As of now all you can do is place turrets, watch them shoot the enemies and that’s pretty much it. Nonetheless this is the gameplay footage: