We’re not in Kansas anymore Toto!

Joe Kuka
6 min readMar 1, 2021

Aloha everyone and welcome to the recap of Week 2! Today marks day 28 of the 100 Day challenge to work on something everyday with GameDevHQ, and just like the title of this article we are no longer in my comfort zone or at least, was not for most of the week. To say this week was challenging would be an understatement of the amount of time effort and frustrations that happened over the course of the week. Starting the week off, I was behind, and not just a little behind but way behind. There were a few concepts that I would really need to get through this week that I had not even learned yet, let alone tried to practice. Some of the key concepts for this week would be, delegates, and events, using scriptable objects (which are amazing BTW), and raycasting. All of these were brand new topics for me along with LINQ(Language Integrated Query), using Dictionaries and getting away from using the GetComponent call as much as possible. It took me the first 3 days of the week just to catch up on the much needed material and many many pages of notes lol.

Once I felt I was all caught up I began with this weeks tasks and it was no short list. Create locations where turrets can be placed, create camera movement functions using the WSAD keys and the mouse wheel for zooming in. And to be honest this was fairly easy having used similar functions before. Utilizing the Input setting built into Unity I quickly created logic that asaigned the WSAD keys to a “Horizontal Input” and a “Vertical Input”. Then After a google search on camera zooming I discovered there is a function on the camera called “Field Of View” and just like almost anything within Unity it can be adjusted if you can access it. After a little bit of research into mouse movement and figuring out there was even an Input setting for the “Mouse ScrollWheel”. The cool thing about these setting being built in means I can take them and assign them to certain things. with the scroll wheel for instance I was able to assign it to the camera field of view so every time you scroll you either zoom in or out in the game view. Check it out!

Camera Movement with WSAD Keys

After this little confidence booster it was time to make my turrets and placement logic. I started out by creating available spots for my future turrets to be able to go. This was done with a 3D game object, and the turning off the MeshRenderer so it looked invisible. Since 3D object come with a collider I knew I could use that to detect when something was hitting it. Below is a picture of the future tower locations before I made them invisible.

Available Tower Locations

After I had my tower locations set up, the next task was to put a particle beam effect on them so when activated they would look like beacons that tell the player you can put a turret here!

After this I created 2 scripts to handle the behavior of my tower locations and then the placement of the towers themselves. The main script I turned into a Manager class since it would be doing most of the work controlling what goes where. The other script lets my TowerManager script know if a location is available and turns the beacons on and off once a tower is placed. This was a ton of “if statements” and “Bool” checking going back and fourth. After a day and a half I had roughly 500 lines of code. You might say wow that’s impressive, but on the contrary it was very messy and counter productive with a lot of unnecessary logic. One of the things we are being encouraged to do is first make the program work and then optimize your code. This can be a little painful for me as I am so new and have been missing major opportunities for optimization, but after this week I am starting to see the picture a little better.

After my Friday check in with our awesome Team Leader Dan I had a really good idea of how and where I could go about optimizing the weeks work. Enter my new nemesis….Delegates and Events. For those of you seasoned programmers out there you already know how amazing and useful these can be, but for me this was the equivalent of asking me to fly to the moon this week. Part of me thought it understood this concept and the other part kept saying “I swear this is rocket science!”. At the end of the day though it was not as bad as I had feared and I feel I have an okay understanding of it to start. To try and wrap this concept up in a nutshell to the best of my current understanding, and Event is when you declare something in one script, and then anyone in any script can listen for that event and decide what to do about it. This is so very useful because normally if you wanted to communicate between other scripts and other game objects you would need some direct reference to the GameObject you are trying to communicate with. This is done by either creating a global variable on your script and attaching the game object directly to it, or by using some form of GameObject.Find to locate the GameObject and then grab the component you need. For the instance of placing the tower though, I was able to create several events/ actions that told the other scripts things like, “We are looking for a location to place a tower, what do you have available?”, or “A tower has been placed, turn off your location”. There is of course so much more to this and as I learn it I will happily share it with you. In order to make the necessary parts work for this week, I needed to create the locations towers could go, and create the particle system that displays you can go here. We also needed a few GameObject decoys to show what you would be placing on your tower location, along with the potential attack radius they would have. and then of course the turrets themselves you would be able to place. This provided a great opportunity to use arrays, and even learn some optimized ways of sorting through them using customized methods! Here’s a look at the decoy turrets with their attack radius.

Decoy turrets with their respective attack radius

Since this week was so tough my Team Lead was kind enough to offer up an additional check in day on Saturday to help fine tune any optimization I was missing, and now 24 hours later I have finally converted all of my code to what I feel is a much better and much cleaner version of two days ago lol. I will touch on ray casting next week since most of my upcoming tasks are related to that. For now though I am going to call it a day and get some much needed rest in preparation for tomorrow. Mahalo for reading and for all of the continued support.

--

--

Joe Kuka

I am a self taught game developer and love pushing myself to learn new things.