Monthly Archives: December 2015

GAM 111.3 Reflective Development Logbook Blog 11 (Week 12)

Week 12, and the final blog post for this trimester.

In this particular class, we didn’t work on any projects or get taught anything. Instead if we had any problems or questions about the game we have been making, our lecturer was more than happy to offer some advice.

One particular problem, one I hadn’t even thought of up until this point (and also that the lecturer helped me point out).

Although the towers were using ray casting to find their targets, and then if the raycast hit a game object with the tag “Enemy” it would instantiate a projectile. But the problem was that the way I wrote the code. The code that is written to make a projectile wasn’t in the ray casting function. So “if” the raycast hit an enemy { make a projectile }, instead it was if the raycast hits an enemy { } make a projectile. So no matter if the raycast hit a target or not, a projectile was being instantiated. So I then put making a projectile inside of the ray casting function.

No projectiles were being instantiated. Why? (Bear with my while I explain).

Multiple different ways were discussed to fix this, but every option wouldn’t work. One of the things that changed in this weeks progress is that the towers no longer contain a box collider or a NavMesh obstacle with carving. Each grid in the grid system did, and when a tower had been placed, it is made a child of the grid its placed onto. When the tower has completed constructing, the grid that the tower is now a child of gets its NavMesh obstacle and carving enabled. That way the enemies always have a clear path to run through rather than towers that rotate and constantly change the available space for enemies to run through causing inconsistencies.

As I mentioned last week, each grid is just a box collider that is a trigger.Inspector raycast

So guess what this means?

Trigger Box Collider

Towers are trying to raycast from INSIDE of the grid (trigger box collider). The raycast never makes it outside of the box. That’s why nothing was instantiating.

So turning off Raycasts Hit Triggers would completely break the grid system, the towers and also the builder.

Luckily the lecturer pointed out that he recalled a way for raycasts to ignore certain layers.

Layer Screenshot

So that’s exactly what I started to look into. And luckily enough it was surprisingly an easy enough fix.

I came across this little gem. (You don’t have to watch this).

Raycasting already have a built in overload that makes them ignore layers!

What my ray cast was:

RaycastHit hit;
if (Physics.Raycast (myTransform.position, -(myTransform.position – closestEnemy.transform.position).normalized, out hit, range)) {DoSomeStuff};

All that I needed to add was  after “).normalized, out hit, range” was “, ((1<<9) | (1<<13)))).

The (1<<9) | (1<<13) says to the raycast only focus on THESE layers. Layers 9 and 13 and ignore the rest.Layers Screenshot

I want the ray cast to hit enemies, and I want the raycast to hit the ground so that ray casts don’t travel through the ground.


Raycasting Working

One other issue that I have is (and is still broken) that if the a second tower is placed while one tower is under construction, the unfinished tower stays unfinished. I’ve added a second building button.

Unfinished TowerEvery tower that is placed and ready to be built gets added to a list. When it is finished being built it gets removed.

So the button makes the builder target an unfinished tower in the list and is supposed to set his NavMesh destination to that tower, and if the builder is close enough to it, hes supposed to continue constructing it.



I’ve also added a way for enemies to destroy towers if their NavMesh path is blocked by checking their NavMesh.pathstatus.

If their path status is partial, they find the closest tower to them and destroy it. If their path status is complete, they continue to run the gauntlet.

The tower’s don’t have an amount of health and the enemies don’t have an attack damage. Including that would have taken more time and required setting up proper collisions to apply damage whilst following the enemies animation (similar how I did in the side scroller project we did in week 8), creating and balancing health variables etc etc. So when an enemy is close enough to a tower, it simply deactivates the NavMesh Obstacle and carving in its parent, then destroys the tower.


Made a main menu scene complete a play button, instructions button with a 4 page instructions, and an exit button.

Completely overhauled the look of the tower defense scene’s UI.

Added a gold nudging menu, so if gold gets stuck under a tower, it can be nudged out for the gold collector to get.

A sell tower button to refund 100% of the towers cost.

Completely overhauled the entire assignment with sounds.

Main MenuInstructions Page 1Game Scene ScreenshotBuilder UITower UIResource Tracker With TimerGold Nudging MenuSell Tower ButtonScene View 1Scene GameplayScene View 2Game Over Menu

Well, that’s my Infinity’s Edge Tower Defense.

Unfortunately that’s the last blog post for this trimester, I hope that the you’ve enjoyed this journey with me so far as much as I’ve enjoyed venturing on it.

This weeks song’s:

And to my lecturer:

Sublime trimester on your behalf.

True Story.jpg


That’s all for now. Enjoy the Christmas time.


Until next time –





Metal Fiery Horns





Information source:

Technologies, U. Unity – Scripting API:. Retrieved 8 December 2015, from,. List(T) Class (System.Collections.Generic). Retrieved 8 December 2015, from

Technologies, U. Unity – Scripting API:. Retrieved 8 December 2015, from


Image source:

All screenshots of this project are my own work – Lyness, N. (2015). Infinity’s Edge Tower Defense Screenshots. Retrieved from

Genius,. (2015). True Story. Retrieved from

DragonArt,. (2015). Fiery Metal Horns. Retrieved from,-devil-horns.htm


Video source:

Thy Art Is Murder Band,. (2015). THY ART IS MURDER – Holy War (OFFICIAL VIDEO). Retrieved from

Foo Fighters,. (2014). Foo Fighters – I Am A River. Retrieved from

Leave a comment

Posted by on December 8, 2015 in Uncategorized


GAM 111.3 Reflective Development Logbook Blog 10 (Week 11)

Week 11


In class this week we expanded on the previous project with mouse clicking and moving objects, and instantiating a prefab.


Now there is functionality to select multiple units by left clicking (and holding) with the mouse and dragging the cursor to a second location in the game scene. If units are inside of the transparent green zone when the left mouse button is released it selects the units inside. And while these units are selected, right clicking somewhere in the game scene moves all the units that are selected to that location.

Multiple SelectingMultiple select and move

This is done by having two variables for mouse positions. When the left mouse button is clicked it casts two rays and instantiates a transparent box collider that is a trigger. One raycast stores the original hit position and the second is always the current location of the mouse. The transparent selection trigger scales between the two locations of the mouse positions. If any unit’s  (game objects with the “Player” tag) are being touched by this transparent trigger box collider (OnTriggerEnter), they’re added to a list. On exit (OnTriggerExit) they’re removed from the lust.

Then to move them, instead of only having the one game object’s move to the mouses right click location, the script does a foreach loop. For each game object in the list. They move to the mouses right click location. If the list is empty, nothing happens.


We also added a button that calls the method to instantiate the prefab for the building, rather than just pressing ‘F’. But as I had already figured this out in the previous week. But something new was when the prefab is instantiated and the raycast is hitting certain objects that doesnt enable the building to be placed it turns red and the building is unable to be placed. When the building is placed it plays a little raise animation that we created.

Button to Make building
Cant place building



My assignment


I’ve  added

+ Bounds for the camera to stop at so it doesn’t continuously scroll.

+ Some textures and learnt how to paint with them &&  a second landscape on the outer of the landscape. It’s surprising how much flavour this gives to the game.Landscape Texture Painting

+ Boundaries so the camera cant move past certain dimensions. This is exactly the same as what we had implemented in the week 2 SHMUP project with the ship. Have 4 variables that are int’s and give each a value relative to a distance in the world space. Two int’s that will store a location for a Z distance and two for the X. So in this case. My landscapes have positioned so that the centre is exactly at (0,0,0, (x,y,z)) The four variables that i never want the camera to move past are 60 and negative (-)55 on the Z axis, and 55 and negative (-)55 on the X axis. In the update function if the camera’s position is ever equal to or greater than any of those set int’s it returns the camera position to that int that its trying to be greater than.

+ A grid for towers to be placed to. 1313 grids to be exact.Grid LayoutEach grid is just a box collider that is a trigger. If they weren’t the enemies wouldn’t be able to run through the landscape. There would literally be a giant wall blocking them. When a tower is in the stage where it is ready to be placed, it still constantly follows the mouse position, but when it’s hovering over a grids location it will stick to that grids position to show exactly where it were would sit if it was to be placed on that grid. If the mouse isn’t hovering over a grid while a tower is still being placed, the tower follows the exact location of the mouses’ position.


+ A Checkpoint system for the enemies to run through.

Each checkpoint is a box collider that is a trigger. Each enemy now contains a bool that is false for each of the checkpoints. When an enemy enters a checkpoint, the checkpoint accesses the enemy’s script and turns the bool of that checkpoint to true.

When each enemy spawns, they roll a random number  between 0 and 2 (because unity’s Random.Range maximum number is exclusive, which means it will only generate a number that is anywhere between the lowest number and 1 before  the maximum number), and find the closest checkpoint to their location and start running towards it.

In an the update function the enemies have a method that makes them RunTheGauntlet() which makes them set their destination to one of the checkpoints depending on which bools are true.

If they touch the first left checkpoint, the destination changes to the bottom left checkpoint,  the mirror for the right side. When they touch either of the bottom of the checkpoints, they run to the bottom middle checkpoint. Finally when they touch the bottom middle checkpoint, they run to the final destination (marked with the orange glowy circle).

But what happens if they spawn in the middle you ask? That’s where the random roll comes into action. When they touch that checkpoint, if the number is 0, they go left. If it’s 1, they go right. Tadaaa.Checkpoint

A small problem that I encountered with the random roll was that I originally had it in the RunTheGauntlet method (which is running every frame). So each frame the enemy is constantly rolling a random number, then when they reach the middle checkpoint the number that is supposed to be a solid 0 or 1 was constantly changing, causing them to be undecided in which checkpoint they should run to. Eventually they would have made it to a checkpoint and continued on. But a simple fix was to call the random roll once when they spawn.


+ Changed navmesh radius on enemy, builder and gold collector so they don’t need to much room to move, so they can overlap and move more smoothly instead of getting stuck.

+ Projectiles for each tower.

+ Wave timing and spawning certain enemies each wave.

Each spawn location holds an array of size (11) to store each enemy, along with a number of enemies to spawn. Every time a wave starts a single type of enemy spawns. The spawner’s choose the same number in the array depending on which wave it is, to spawn that specific enemy.

+ A Coroutine when the game starts and when each wave is finished to start a countdown timer for the next wave to spawn.



I’ve met all of my plans that I wanted to from last week.


Problems encountered


Final decision on which texture to use for the landscape 😛

A small amount of time spend on the random roll bug.

Figuring out correct syntax to make the towers that i’m placing stick to the grids location. (Once I figured that out, making the towers location do the sticky grid, while the cursor was moving was easy)

Constant null reference exception errors popping up if the camera’s raycast isn’t hitting anything.



Next weeks plans


Game over menu.


Main game scene.

Try to work out if the enemies NavMesh path is blocked and put them into an attacking phase.

Clean up a few inconsistencies.


This weeks song:


Until next time –




Information source:

Technologies, U. (2015). Unity – Scripting API:. Retrieved 1 December 2015, from

Technologies, U. (2015). Unity – Scripting API:. Retrieved 1 December 2015, from,. foreach, in (C# Reference). Retrieved 1 December 2015, from 

Technologies, U. (2015). Unity – Scripting API:. Retrieved 1 December 2015, from

Technologies, U. (2015). Unity – Scripting API:. Retrieved 1 December 2015, from


Image source:

Lyness, N. (2015). Multi Select Screenshot. Retrieved from

Lyness, N. (2015). Multi Select Move Screenshot. Retrieved from

Lyness, N. (2015). Building Can Place Screenshot. Retrieved from

Lyness, N. (2015). Building Can’t Place Screenshot. Retrieved from

Lyness, N. (2015). Tower Defense Updated Landscape Screenshot. Retrieved from

Lyness, N. (2015). Grid Layout Screenshot. Retrieved from

Lyness, N. (2015). Checkpoint Screenshot. Retrieved from


Video source:

EpitaphRecords,. (2015). Parkway Drive – “Dark Days”. Retrieved from

Leave a comment

Posted by on December 1, 2015 in Uncategorized