Recap – Week of January 13 to January 20

January 20, 2019

Recap – Week of January 13 to January 20

Thesis Work

Continue to search for some research on the general term of “game mechanics” to solidify the use of its definition as well as determine the components that make for interesting variable mechanics.

Terminology to Look Into – Programming

Structs

Structs were a big part of the field of vision tutorials, and I still don’t fully understand how to utilize them. They are structured data containers that can hold many types of variables to use over and over, but I’m not sure if there’s more to them to help utilize them, especially for games. Could help to look into a tutorial where there are characters or enemies with stats (i.e. RPGs), or a pokemon-like tutorial (well, also under RPG).

Field of Vision Recap

Youtube – Field of view visualisation (E03: stencil shader)

By: Sebastian Lague

To start, I just wanted to include that there is a 3rd part to this tutorial series I would like to get to. The field of view (FoV) tutorial was really useful for learning several aspects of Unity programming overall. I learned more about creating Editor elements for making your scripts into more designer friendly tools. I was still getting some weird interactions with the GetAxisRaw command I need to look into. This was also a nice refresher on generating meshes within script, but the extra twist of tying it in with raycasts was something interesting, new and useful.

Learning Foundations of Unity Shaders

My Blog – Learning Foundations of Unity Shaders

This was my first time learning about shaders and getting into the Shader Language and scripting anything, so I was introduced to a lot of new concepts and terminology. I covered it pretty extensively in the blog post, so I just relinked it here. These tutorials made by Unity in several steps are usually very informative conceptually as well as programmatically.

Quadtree and Octree

These data structures for use in games seem like they could be very useful for some things I am interested in since they seem like they can be pretty computationally beneficial if you want to have wide reaching field forces interacting between many different objects. I will still need to do more research into this, as well as find more tutorials as they were hard to find.

Intro to Quadtree and Octree in Unity

January 19, 2019

Quadtree and Octrees

Intro to Oct/Quadtree Data Structures

These sources begin to explain what quadtree and octree systems are and their potential uses in a game environment. There are a few tutorials attached as well explaining how to set them up with programming. Searching for these topics did not turn up a lot, but these few sources seem to be good starts.

Youtube – Lets Make an Octree in Unity

By: World of Zero

This is a basic approach to just setting up an Octree system in Unity in general.

Youtube – Building the Quadtree – Lets Make 2D Voxel Terrain – Part 1

By: World of Zero

This is the result of a challenge to the creator to make a Worms-style terrain destruction system. This would be approached by creating a 2D voxel system.

Youtube – Coding Challenge #98.1: Quadtree – Part 1

By: The Coding Train

This video gives a very good conceptual introduction to what a quadtree really is and the uses of it in programming. It then sets up how to create one in javascript.

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.

Field of View Tutorial E02 – FoV Mesh – by Sebastian Lague

January 16, 2019

Field of View

Tutorial – E02

Youtube -Field of view visualisation (E02)

By: Sebastian Lague

This is the second part of a tutorial creating a field of view (FoV) for a character in Unity. This focuses on an in-game visualization of the field of view that fills the entire viewing area. FoV visualization is a generated mesh. This will be built from tris made up by the character’s position and the end point of each ray cast within the FoV.

A struct was created to hold all of the information for the raycasts. Used transform.InverseTransformPoint to convert a point (Vector3) from a global value to a local value.

The FoV mesh initially had an issue dealing with the corners/edges of obstacles. A high resolution was needed (many rays cast) to reduce the visual jitter effect around obstacle corner/edges. This was addressed further in the tutorial. To solve this, approached the problem by determining when rays go from hitting obstacle to missing obstacle, and label these “min” and “max” values. We know edge must be between these two rays somewhere. Then you cast rays directly in between these two rays until you find the edge/corner (or somewhere very close).

This solution helped the case of the FoV mesh hitting an obstacle very well, but still had issues if the two sequential view rays hit two different objects. This case has both rays hitting an object, so the logic determines this case is fine, however it produces a similar problem to what we had before. To fix this, a distance threshold between the two ray hit locations was added. This assumes two points hitting far apart were most likely parts of two different obstacles. The solution appeared to make the FoV mesh much smoother.

PROBLEMS

My FoV mesh was glitching out sometimes when interacting with obstacles. Some of the points of the mesh were jumping to very far away and incorrect positions. This did not appear to happen at all in the tutorial video, but happens pretty frequently with my setup so it may just be a typing error within the code somewhere. I will have to investigate to determine the issue.

SOLVED

The tutorial provides the scripts through github, so I was able to compare them side by side and find the error. It was a typo. In the DrawFieldOfView method, in the check to see if the sequential raycasts hit the same type of thing where they are checking for the edge cases, they add either pointA or pointB to the viewPoints list depending on which one is not equal to zero. I had both of these cases adding pointA specifically, which is what was causing the very strange mesh shapes sometimes for cases where my Fow was hitting obstacles.

Field of View Tutorial E01 – by Sebastian Lague

January 14, 2019

Field of View

Tutorial – E01

Youtube -Field of view visualisation (E01)

By: Sebastian Lague

This tutorial sets up a field of view (FoV) for a character. This FoV gives basic sight to a character. This sight has a radius and a viewing angle, and it is blocked by obstacles. This FoV also has a global setting that determines if it follows the character’s rotation or not. There are also editor elements that make it visually very clear what is happening by drawing out all of these factors.

Unity angles: Normally we start with 0 degrees to the right of the circle, but Unity starts with 0 at the top of the circle (where you’d normally have 90 degrees) for its angular math calculations. Since sin (90 – x) = cos x, this just means we swap sin and cos in Unity math.

PROBLEM

I had an issue with GetAxisRaw command not working for mouse inputs with the axes being “Horizontal” and “Vertical”. It just constantly returned a value of 0. This was ok with keyboard inputs however.

Unity Basic Enemy AI Patrolling

January 12, 2019

Unity Basic AI

Patroling

Youtube – PATROL AI WITH UNITY AND C# – EASY TUTORIAL

This tutorial just sets up a basic patrolling AI where empty gameobject waypoints (called movespots in the tutorial) determine the enemy’s movement. It used an array of positions which contained all the possible waypoints, then randomly selected between them and moved the enemy there. This movement isn’t particularly useful for much, but it showcased a basic waypoint system well enough.

This tutorial actually attempted to correct the issue I brought up from the previous tutorials in my last blog where they were using if statements that ended when a position exactly equaled another position, which was very susceptible to math errors. They even used my quick (but still not great) work around of using distance and “less than” to set a small acceptable range to account for these small math errors.

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.

AI Project Research – Looking for Inspiration

January 9, 2019

AI Project Research

GDC 2018 – AI Wish List: What Do Designers Want out of AI?

By: Raph Koster, Dave Mark, Richard Lemarchand, Laralyn McWilliams, Noah Falstein, and Robin Hunicke

GDC 2018 – AI Wish List: What Do Designers Want out of AI?

I’m bringing back a video for reference to try to come up with an AI intensive project. There are lots of quotes and the notation is very note-y, just using it to keep track of points of inspiration.

Laralyn mentions that she wants AI to be able to acknowledge that what the player is doing is unique. The way they are playing is differentiating from what is expected, and it should be noted by surrounding characters. Could we apply a type of “physical constraint” concept to this to help accomplish this goal? Physical constraints mathematically map out what an equilibrium should be, and then apply forces/actions to bring things out of line back to equilibrium. Could we use this concept to perform AI actions when it acknowledges a player diverges from what is expected, the “equilibrium” of the player experience?

From Raph Koster, “…building characters as props that are primarily reactive, and if we want to exploit AI, they need to have their own inner lives, out of which this stuff rises organically.”

”Heartificial Intelligence” – giving NPC’s empathy; Have deeper version of Sim system. Users more interested in “broken” characters with flaws. A dog that is scared of people now and is harder to train. Problem with Sim system was that every object had to echo out how it should affect an NPC, and they all needed to interact with each other so adding things to the system was very difficult(?).

Time Stamps: (0:49:40 – 0:51:18) : AI can be recursive and add detail. “…Can you do that but in a way that is data rich, instead of just going for ‘no let’s plot thousands of trees’, how about when I go look at that tree it’s way more detailed. Now there’s an ecosystem in that tree. Now there’s a burrow in this one and the gophers live under that, and there’s a woodpecker in that one. That’s the kind of detail we will never ever be manually able to do. We just can’t afford it, it’s ridiculous. And it’s exactly the kind of intelligently constructed, realistic, responsive environment. You want the woodpecker to know there’s a gopher. I’m not talking just shallowly, again, it’s not just splatting the textures. Can we actually create a data rich environment? … it’s a fractal or segmented thing. We don’t need each tree to know about each tree. But we could do something really interesting within the tree… each one could have variations.”

Solaris example – it builds things from your memory; makes you miss being on earth

”…go to a foreign planet and you find an object, and when you look inside that object there’s more objects, and you look inside those objects; and then come up with a design of mechanics that are interesting from the exploratory perspective that’s very similar to when you’re a child. When you wander into your backyard, and then the woods there and you find a stream then you look in the stream and you see the tadpoles and then you poke the tadpoles. Think of it from a mechanical perspective, not an aesthetics perspective, and then you get the dynamics that are so interesting.

Decentralize player, other things go on without the player. Make the player feel proud of something else. Have an AI do something the player didn’t expect it to do. Going off of this: Have an AI that the player needs to “teach” it how to do something with their actions. Similar to “Clumsy Ninja”.

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.