Tower Defense Tutorial – Brackeys – Ep. 04

January 24, 2019

Tower Defense Tutorial

Episode 04 – Turrets

Youtube – How to make a Tower Defense Game (E04 TURRETS) – Unity Tutorial

By: Brackeys
Ep. 04

This starts the creation and implementation of the turret objects.

Use OnDrawGizmosSelected to show important editor information when an object is selected. In this case, DrawWireSphere was used and it showed a wireframe of a sphere with a radius corresponding to the range of the turret.

Wanted turret to update to find targets to fire at, so method UpdateTarget was created. This is going to be relatively expensive using distance checks so it was made as a separate “Update” method so we could run it much less than every single frame. This method was then called in Start with an InvokeRepeating call, which lets you set a time to start running, and a time interval to repeat the method.

Rotating the turrets required usage of Quaternions. First, the direction was obtained with a simple Vector3 between the object and target. This was converted to a Quaternion variable with Quaternion.LookRotation(). It was then converted back to an angular measurement, which was another Vector3 variable that took the Quaternion and just applied .eulerAngles to it. Finally, that angular value was passed specifically to the transform’s rotation value as a Quaternion.Euler rotation vector (which we just passed the y portion of our rotation vector to the y portion of this rotation vector). So keep in mind dealing with angular movement may require lots of back and forth with angles and quaternions.

PROBLEMS

There was an issue where the turret rotation was off by 90 degrees, so the tutorial solved this by separating out the prefab and rotating the rotationPoint(partToRotate) that was an empty parent object of the intended object needing rotation by -90. The child/parent relationship was then put back together and the prefab was reassembled. I decided to just add 90 degrees to the y rotation of partToRotate in the script when assigning the rotation and this worked fine. However, when we changed the method to add a Lerp for the rotation, this broke my solution. This makes sense because the Lerp wanted to go between the partToRotate original rotation and the new rotation, neither of which had my additional 90 degrees in it. Then when it would go to assign the new partToRotate.rotation with my additional 90 degrees and go back to Lerp again, the value was then way out of the original range. This gave a crazy looking jittery effect. This has taught me that I don’t understand Quaternions at all and will need to look into those in the future.

Tower Defense Tutorial – Brackeys – Ep. 01, 02, 03

January 23, 2019

Tower Defense Tutorial

Episode 01 – 02 – 03

Youtube – How to make a Tower Defense Game (E01) – Unity Tutorial
Youtube – How to make a Tower Defense Game (E02 Enemy AI) – Unity Tutorial
Youtube – How to make a Tower Defense Game (E03 Wave Spawner) – Unity Tutorial

By: Brackeys
Ep. 01

Created all the nodes in grid that make up the map. Created the ground out of scaled cube objects as well. Added start and end location as simple cubes for now.

Ep. 02

Creating the enemy AI with waypoints. A static transform array was created to contain all of the locations of the waypoints. There was an issue where we got an “index out of range” error because the enemy was looking for another waypoint to go to when it was supposed to be destroyed. It was being destroyed, but since that can take the computer some time to do, it was continuing into the next lines of code before the object was completely destroyed. To solve this, a return; line was added in the if statement for destroying the object to ensure that process finished before doing the rest of the code.

Ep. 03

This was creating the wave spawner for the enemies. The spawner needs a timer to control how often and when it releases waves. The approach used here was a countdownTimer that was reduced by time.deltatime in the update method.

Enemies however were being spawned directly on top of each other all at once for each wave. Coroutines were the choice to resolve this issue. Coroutines are useful to run functions separately and side by side with the main functionality of the code.

List of Tower Defense Tutorials for Unity

January 21. 2019

List of Tower Defense Tutorials for Unity

How to make a Tower Defense Game (E01) – Unity Tutorial

By: Brackeys

This is the start of a 28 episode series for creating a tower defense game from scratch. It is mostly 3D, although the game plays in a 2D environment.

0.0 Unity Tower defense tutorial – Introduction

By: inScope Studios

This is a 2D sprite tower defense game that uses tiles/grids to create its levels and environment. It also includes a lot of nice smaller tutorials along the way like creating a loading screen, some options screen elements, hovering for information boxes, etc.

1 Hour Programming: A Tower Defense game in Unity 3d [Tutorial]

By: quill18creates

This is a quick “speed run” of creating a basic tower defense game just to see if the creator could get one up and running in about an hour. This may not have the best practices, but can be good for finding some of the bare minimum requirements for getting a tower defense game off of the ground.

Learning Foundations of Unity Shaders

January 18, 2019

Intro to Shaders in Unity

Glitchy Man Material

Unity3D – Live Training Session: Writing Your First Shader In Unity

This tutorial was pulled from the tutorial list I created January, 17th (“Assorted Unity Tutorials – Structs, Shaders, and Unity Architecture”). IT not only introduced me to the core components that make up a shader in Unity, it also covered a lot of terminology and behind the scenes information to give me a better foundational understanding of how shaders operate.

Types of shaders you can create in Unity:
  • Surface Shaders: code generation approach that’s easier to write lit shaders than using low level vertexe/pixel shader programs
  • Unlit Shaders: don’t interact with Unity lights, useful for special effects
  • Image Effect Shaders: typically postprocessing effect that reads source image, does calculations, and renders result
  • Compute Shaders: programs run on graphics card, outside normal rendering pipeline; used for massively parallel GPGPU algorithms or accelerate parts of games rendering
Explaining Basic Shader Script

Shaders go onto a material. Determines how a material is rendered. Standard for Unity shader uses Shader Language. The Properties block is similar to public variables in Unity, as they can be seen in editor. The Pass block is where script passes logic to renderer. Tags explain how it wants to be rendered. The two structs (data functions) pass into main functions. These are the vertex function (vert) and the fragment function (frag).

Core Terminology for Shader Scripts
  • Vertex Function: takes shape of model and potentially modifies it; gets the vertices of model ready to be rendered; converts form object space to clip space (relative to camera); result goes to fragment function
  • Fragment Function: applies color to shape output by vertex function; this paints in the pixels
  • Property Data: colors, textures, values set by user in inspector
  • LOD (Level of Detail): this goes with how detailed object is (usually associated with idea in games where closer objects have higher detail and far objects have low detail)

Shaders do not use inheritance. Most classes in Unity start as Monobehavior, which gives you a lot of nice base functions. Shaders need that included, which is what the line { #include “UnityCG.cginc”} is for. This includes the use of a bunch of helpful helper functions.

Two important structs: appdata and v2f. appdata passes in information of vertices of 3D model. These are passed in in a packed array (variable with 4 floating point numbers: x, y, z, w). POSITION is a semantic binding, this tells shader how something will be used in rendering. V2f is short for “vert to frag”.

Coordinate system translations:

Local space -> World Space -> View Space -> Clip Space -> Screen Space

Looking into fragment sections

Fixed4 can either be: x,y,z,w or for color, r,g,b,a. Created a variable _TintColor in properties, which showed up in Unity inspector under the Unlit_Hologram material. This then needed to be used in the CGPROGRAM to actually do anything. We added this color to the fixed4 col found in fixed4 frag, which “adds” the colors together.

Making a transparent Shader

First, changed RenderType in Tags from Opaque to Transparent. Also needed to add “Queue” = “Transparent” here, as the order things are rendered is also important. Because of this, you want other things rendered before rendering the transparent thing because you want the transparent thing rendered “on top”. There are several primary queue tags that exist for rendering order. The following is the order of rendering generally, from first to last.

Primary Queue Tags for Render Order:
  • Background (first, back)
  • Geometry (Default)
  • AlphaTest
  • Transparent
  • Overlay (last, top)

Add ZWrite Off keyword. Tells us to not render on the depth buffer. This is usually done for non-solid objects (i.e. Semi-Transparent).

Displacing vertices and clipping pixels

Using the function “clip” in frag function to clip out pixels within a certain threshold. Adding sin function along with several variables (Speed, Amplitude, Distance, Amount (Multiplicative Factor)) into vertex function to move vertices around in object space, relative to the object. This is done before passing into the frag function. _Amount was a factor in a range between 0 and 1 just to control how much the shader effect was happening. The amount was important for the C# script used to control the effect on a time based interval. The C# script, HoloManGlitcher, could access the variables within the shader script. This was done simply through the material. (i.e. holoRenderer.material.SetFloat (“_Amount”, 1f); )

Assorted Unity Tutorials – Structs, Shaders, and Unity Architecture

January 17, 2019

Unity Tutorial Assortment

Structs, Shaders, and Unity Architecture

Youtube – HOW TO MAKE COOL SCENE TRANSITIONS IN UNITY – EASY TUTORIAL

By: Blackthornprod

Youtube – Beginning C# with Unity – Part 15 – Structs

By: VegetarianZombie

Youtube – Reduce Garbage Collection in Unity with Structs

By: Unity3d College

Youtube – Unity Architecture – Composition or Inheritance?

By: Unity3d College

Youtube – Shaders 101 – Intro to Shaders

By: Makin’ Stuff Look Good

Unity3D – Live Training Session: Writing Your First Shader In Unity

By: Unity

This is juts a list of some useful resources of tutorials for some things I would like to get around to soon. They cover some basic functionalities of Unity, as well as some more in depth programming concepts to help aid in building my code.

Unity Basic Enemy AI Following and Spacing

January 11, 2019

Basic Unity AI Tutorials

Player Following and Spacing

Youtube – AI TUTORIALS WITH UNITY AND C#
Youtube – SHOOTING/FOLLOW/RETREAT ENEMY AI WITH UNITY AND C# – EASY TUTORIAL

By: Blackthornprod

This first video used the Unity command “MoveTowards” which I thought was giving me some issues so I just created my own follow AI using simple vector math (this was a good opportunity to brush up on vector math again). It turned out everything was fine and both ways worked, but I like really knowing the math behind what my objects are doing. The addition of a stopping distance so the enemy stopped moving towards you at a certain distance was a nice extra touch that’s very easy to add with a simple if statement tied to distance between player and enemy.

The second video was a bit more interesting by having the enemy have 3 ranges: vary far away, away, too close. At very far away, it moved closer. At away, it stayed in position. At too close, it would move away from the player. This could be a good setup to test setting up a small state machine to get practice using those with AI. I could have each of those be a state and use an enum switch case setup to decide which action the enemy should use.

This was also a nice little refresher on instantiating projectiles, although the logic for them was strange and bad. The projectileScript class would get the position of the player and then end at that position. This was then “remedied” in the tutorial by having it destroy itself when the projectile position was equal to that original target position, but math errors were preventing them from EXACTLY matching the value for me, which kept them from being destroyed. As a quick solution, I just changed the if statement to occur when the distance between the projectile’s position and the target position was less than 0.1, so it just had to be pretty close, which allows for some math errors. I imagine this is not a great solution either though as calculating distance in Update for a projectile constantly sounds too aggressive computationaly.

Various Video Tutorials – Tactics Programming and Game Design, Tilemaps with Hexagons, C# Enum, Sharing Between Classes

January 8, 2019

Video Tutorials – Programming and Game Design

Youtube – Unity 5 Tutorial Tactical Turn Based Game Part 1 Basic Grid Movement

More turn based tactics game programming to learn another way to approach them, as well as get further into actions and combat.

Youtube – MAKING ISOMETRIC TILEMAPS in Unity 2018 | Beginner’s Guide (Tutorial)

This is just a simple tutorial showing how to use some new Unity features for dealing with hexagonal tile setups and isometric tile maps.

Youtube – Final Fantasy Tactics & Combat Initiative Systems | Game Design Guide

This video goes over some terminology and game design pros/cons for different ways to approach tactics combat systems.

Youtube – The Key to Making Turn Based Games! – C# Enum Tutorial

This video explains the basic concept of using a simple enum for setting up states for a turn based game. There are more links to all of the code included as well.

Youtube – Easiest Way to Share Behavior Between Classes in Unity – C# Interfaces Tutorial

This is a general programming tutorial for a way of sharing behaviors between classes in Unity.

Pawel Margacz – Generalist to VFX Artist – Learning VFX

January 7, 2019

Good Sources to Learn About VFX

80.lv – Link to Description

A quick write up by Pawel Margacz on how they got into VFX and how to learn the art. This included a few good youtube channels to follow to get helpful tutorials.

Youtube Channel – Mirza VFX
Youtube Channel – Sirhaian’Arts
Youtube Channel – ErbGameArt

These three channels offer great tutorials and showings for VFX. Mirza in particular has Unity specific examples with all of the work needed in multiple softwares (such as creating images in Photoshop to use as base for VFX in Unity).

Learning Tactics Movement (Cont.) – BFS and Collections

December 22, 2018

Tactics Movement (Cont.) – Programming Collections

Breadth First Search (BFS) and Using Programming Collections

Unity Tutorial – Tactics Movement – Part 3

By: Game Programming Academy

This section begins to finally create the breadth first search algorithm for creating list of available selectable tile options. This section relies heavily on collections type elements in C# programming which I will need to delve into more.

Notes

Look into breadth first search, stacks, queues, and lists.

Stacks: Used to add things to a collection in a certain order and use/apply them in reverse order. Stack uses command “push”.

Queues: Use “enqueue” to add to queue and “dequeue” to remove/pull from the queue.

halfHeight was a variable used to find the center point of the game object in conjunction with the “bounds” and “extents” values of the collider. This is used when positioning the unit on a tile to make sure it is on/above the tile.

Lessons Learned

Had an issue where the mouse clicking functionality wasn’t working. It turned out that the main camera just was not tagged “maincamera”. Make sure to check camera labeling and that it matches what you call out in code when dealing with functions that deal with screen space and the camera.