Since the last update I have made a lot of changes to TDX-2. I took a step back from the multiplayer part of the game and instead focussed on getting the pathfinding and the AI agents movement behaviour right.
For the navigation of the ai agents in the game i made the choice to go with Aron Granberg’s A* Pathfinding Project Pro instead of Unity’s built in navigation system. Mainly because it’s going to be a grid based game, and the A* PPP has the option to use a point graph for navigation instead of a navigation mesh type graph.
For the points that the point graph consists of I can now just use the same nodes positions that I had already setup for the tower building nodes grid. This way the AI agents movements are related to the spacings of the building nodes grid, which gives it a very nice mechanical or computer-like feeling IMO:).
After a lot of experimentation, trial and error I have most of the movement of the agents correct. I have also worked on a lot of small gameplay elements that are necessary for a tower defence game:
- The option to set a target for the players soldiers.
- The option to enable or disable ‘energy sources’ for the players workers to go to.
- Making sure AI agents don’t fall of the edges of the map pieces (used raycasting instead of invisible wall colliders).
- Making a function so that buildings can be destroyed by the player.
- Making a custom editor for the building nodes setup script so maps can be built a lot easier.
- Organised the collision layers, tags, the AI agents colliders and triggers so the things that don’t have to collide with each other don’t and the AI’s triggers don’t get triggered by things that don’t have to trigger them.
- Organised a lot of prefabs and improved the level scenes template so maps can be built easier.
- Made a better units and buildings selection UI that pops up in the center of the screen when the player presses the right mouse button.
- Made a custom local avoidance obstacle with a cylinder shape that can have it’s number of segments adjusted to make it more, or less round.
- Gave all the units, walls, turrets their own health and building costs.
I also experimented a little bit with A*’s RVO based local avoidance system which is basically a way for ai agents to try to steer around other agent’s while looking ahead in time. The behaviour that you would expect from a crowd of people, when you try to move trough them, is that when you get close to another person that they move, or try to move, out of the way for you a little bit so you can pass trough. Which is what the RVO(Reciprocal Velocity Obstacles) local avoidance does:
It’s been used in a lot of games but I cannot tell you how much fun it is to have this setup for myself and to mess around with it!
All in all it’s starting to behave more like a real game, the next thing on the list of things to improve is the enemy AI’s wave spawning to make it spawn different kinds of waves instead of just one. Also, I’m really thinking hard about what direction I want to go with the graphics for this game, because I want it to have it’s own unique style. Turns out that it’s very hard to come up with something new if you want to stick to the whole retro-neon-arcade type of graphics feeling. Any ideas that you might have are welcome so feel free to post your suggestions in the comments!
AI agents nicely making their way trough obstacles while avoiding bumping into each other
A difficult problem I had was finding a good way to deal with completely blocked paths. As it turns out it’s better to not block agents paths completely by setting nodes to ‘unwalkable’ but instead give the connections to nodes that should be blocked a really high ‘cost’. This way the path will always find the ‘cheapest’ way trough obstacles even when the path is completely ‘blocked’ by them. This avoids agents getting ‘confused’ when their paths are blocked and to not have them try to go in a straight line towards the target and ignoring the navigation graph.
My setup script for the building nodes grid uses a custom editor script which allows it to have these nice looking buttons! Makes setting up a map feel a lot more professional:)
The new basic setup for the player’s unit and building selection screen. The names will be changed to images later on of course.
Current state of the level template which contains all the necessary level elements needed to build a new map quickly.
The custom built RVO obstacle in green lines, which allows me to set up the number of segments it should have so it fits the shape of the obstacle better.