In the first blog post from Bagged Milk Studios, AJ and Brian will be reporting on what they’ve been working on for this first week of the project. First AJ will explain how he implemented unit selection, then Brian will explain how he made the units come alive!
In almost every real-time strategy (RTS) game ever made, units can be selected either by dragging a screen-space box around them (called boxing), and by clicking on units directly. This seems like a simple feature, but it comes with a plethora of unforeseen problems. The majority of my time last week was spent experimenting with several methods for selecting units to find the best one.
For box-selecting I ended up choosing the method of checking each unit’s minimum and maximum bounding box points in screen space against the selection box. This is an efficient solution which seems to work well with the size units will be on screen. A unit’s bounding box is visualized below.
For single unit selection, Unreal Engine supplies a few built-in functions which make it trivial to determine if a unit is under the cursor when clicked.
AI is going to be a big part of our game, so it’s important that we have strong behaviors to provide a challenge for the player.
We need to give the units the ability to move! Whenever the right mouse button is pressed, and there are units selected, a check is made to see what object is under the cursor. If there is one, we need to check if the object selected was indeed an enemy unit! If it was, the unit will move in range and start attacking. If it wasn’t, it will just keep following this target (If you target a friendly, your unit will follow that friendly). If there was no object, we make the unit go to the clicked location. We run into some issues though. What happens when the unit you’re clicking is dead? In that case, it will use the click location, instead of setting a target.
Let’s say you right-clicked an enemy, what happens when you get into range? Your unit will start attacking, and it will take into account damage, rate of fire, enemy health and armor. Your damage will apply every X-amount of seconds (depending on rate of fire). The damage is then reduced by the enemy armor, but clamped to be between 1 and the damage, so that every unit will always do 1 damage to a target with lots of armor. Once a unit’s health hits 0 or bellow, it dies. Health is indicated with a health bar above the unit.
When a unit dies, it will go into rag doll mode. This makes killing a squad more immersive, as you can still see the bodies after the fight. We’ll have the monitor the performance of this.
Thanks for reading! Stay tuned for more updates as the game progresses to completion!