Originally a part of the coding post, targets proved to be one of the most complicated things to make through the course of the semester. The base was done fairly early on but in testing, many values needed to be changed and when multiplayer was implemented the targets were the root of many issues.

Variables of the Target Controller

Like the bullet controller, the target controller works by moving objects between two lists and manipulating them depending on the list. Unlike the bullet controller however, the objects of the target controller were not all going to be identical.

The target prefab is the asset with the base target. The bullet target is the instantiated target. Originally, targets were split into 3 different classes that inherited from a base class. This set up was eventually scrapped to keep the code simpler to manage in my head. A more in depth explanation of this can be found in the post for the targets themselves.

In the beginning, there were multiple game modes planned. In an attempt to save myself extra coding in the future, I created the spawning case, which controlled which kind of targets are spawned. With only three targets, the spawning case decided if the controller made stationary, strafing, oscillating, or all three targets.

Originally, there was going to be no limit to how many targets would be spawned. A talk with my technical advisor, Hosni Auji, made me change it so even if a great number of targets could be on screen at once, there would be a cap. Multiple playtests eventually led me to bring that cap on target count from well over 100 to 20. Twenty targets was a nice sweet spot. The targets were numerous enough that the player was never locked onto a single target because of no other options yet not so numerous that the player couldn’t see the environment around them. The count was also low enough that the chances of targets moving into each other was kept relatively low, something important since the player could not shoot all the targets that popped up.

Every frame, the target controller checks all active targets, updating their location if the target hasn’t been shot and putting it away if it has. Beyond the first twenty targets, new targets aren’t instantiated. Targets from the inactive list are modified and placed in the active list again. This caused a bug when a target is hit. Though the target is deactivated, it stays in the same world space position. When the target is re-enabled, it appears in its previous location on the very first frame, making it look as though the target blinks in and out when the player shoots it.

While most functions I use are void, I went with an IEnumerator for the target spawning because it allowed me to recursively call the function easily. If there were less than 20 active targets, the function would either take an inactive target or spawn a new one.

The controller had variables which mapped to the parameters of the different kinds of targets. Certain variables, name the origin, were created later in order to more easily control the targets. Originally, the “center” of all the targets was the player. This caused problems because if the player moved close to any walls, targets could be spawned outside of the players view. The origin was instead set at the very center of the room. The speed of the targets was something I tweaked a lot. In the range of 0.5 to 1.3, the targets had a good variety of speeds without every going so fast they’d be nearly impossible to hit or so slow that shooting them was trivial.

For each type of target spawned, the target controller generates random values for the target to follow. The Target class has functions that sets up each individual target type. Originally, there was a single method that just generated random values but when multiplayer was included, that method had to be scrapped to avoid different targets being spawned between clients through the same method.

When a target is done being set up, it is added to the active targets list, its active boolean is set to true and the target is made visible to the player.