Since last week I temporarily held off doing unit formations while I looked further into the collision avoidance. So while doing that on the side I decided to look into the alternative that workers use instead of formations.
The idea of the formations is for military units as they would have the training to actually follow a formation. Workers would not receive this training and wouldn't actually follow formations. Instead, they freely move to different places. This week I focused specifically on the ordering of workers. So already you can tell one worker unit to build and gather. Which for workers is almost their entire job. But they also do have the capability to attack. So first thing I did was change up my game to support teams based on an enum set in the game manager. Every unit and building now has a team variable. I then set a second town centre to be spawned away from the first that acted as player 2's base of operations with 3 workers spawning at it. Small adjustments had to be made to actually disable the ability to control the enemy's units as they are identical to the players except for this team variable. It also had to be changed that when you double clicked on an enemy unit it would just select then deselect like resource nodes and if you double click on friendly units it wouldn't select the enemy units. This is part of the way done, more changes need to be made as you can train units at the enemy town centre, but at least enemy units.
With having a completely static opponent I also created the basics of being able to attack an enemy. Using some scriptable object setup earlier in the project development I had units' attack for their damage against an enemy unit every second when they are within their set range of a target. It then deducts the friendly units' damage from the enemy's. When the target hits 0 or less health the friendly units will stop attacking. The unit is not yet destroyed as there is likely to be a bunch of lists that need to have its reference properly removed to prevent further problems.
The static enemy and combat was added to allow me to focus on something a little bit different for the early part of the week and form a good foundation to continue both combat and enemy teams. But the main focus this week is a really basic mechanic, but something that wasn't implemented just yet and needed to be. This was sending multiple workers to do one order. This is a more than likely case in any given RTS game where you send multiple units to build or gather something. All my code leading up to this was supported for this as I knew it needed to be done, and did work if you sent units individually to work on something but it got tedious very quickly. So I finally spent some time implementing a way to do it. The reason it wasn't working before was down to one simple error, which occurred when the player clicked to send the unit to either a building or resource. This error was that all units ran the code at the same time, meaning one units would be sent, but the others would throw up the error saying the node it is targeting isn't walkable. All I had to do was use a queue system to sort this out and have the workers check for their path after the previous one had already got theirs. Thankfully this is per frame so the delay isn't noticeable at all. This worked, but unfortunately there are a couple of different instances that needed queuing so a new script was made that simply contained a few functions, some of which were just overloads that supported the different parameters whether a Raycast for movement or a GameObject as its direct target. After implementing these workers can now be sent and each arrive at a different target location when they arrive.
Although working effectively, like my other implementations this week it requires further work to be working as best as it can. This further work is to see what happens when more workers are selected to go to an object than there are spaces (for example sending 10 workers to a resource node that has only 9 spaces). I have an Alpha Demo to present my game this week so a lot more work will be spent on polishing the mechanics that have been created so it can be somewhat smooth rather than expanding on new areas such as combat just yet.