AStar for 2D Pathfinding in Unity

June 8, 2019

Unity 2D Pathfinding

Using AStar

Youtube – 2D PATHFINDING – Enemy AI in Unity

By: Brackeys

This tutorial shows how to setup the general AStar package in a 2D Unity project. It goes over the basics of setting up an initial grid and getting a basic enemy AI that will make the enemy follow a target. It also has an example to setup your own simple AStar enemy AI script using AStar’s Pathfinding package.

This tutorial also cover the basics of setting up an enemy object with a graphics child object, flipping that graphic when the enemy should be going another direction, and just moving an enemy with physics and forces in general, instead of just updating position.

Dev Tutorials Breakdown of Creating Entire 2D Game in Unity

June 6, 2019

Unity

Full 2D Game Process

Youtube – [Unity 2019 Tutorial] 01 Building the Base for Game – Complex Adventure Game With Unity

By: Dev Tutorials

This set of tutorials as an in depth guide on the full process of setting up everything for a 2D adventure game in Unity. This gives a nice overview that can help me see what goes in to really bringing everything you create together to make the single, coherent game in Unity.

Objects Follow Player in Formation

May 16, 2019

Follow Player Script for Unity

Follow with Formation and Noise

Vimeo – Demonstration of the FollowFormation Scripts with Noise Features

By: Me

This clip just shows off the different aspects and functionalities for my FollowFormation scripts so far.

I was working on a system in Unity for a class project that would allow a player to collect objects around the map by running into them, and then they would follow the player around in some sort of formation. This ended up working better by splitting the concept up into two classes: Leader (on the player object) and Follow (on the following objects).

Leader script

Since we wanted to control the general formation of these objects as well, we’ll start with the Leader script. To make a simple and easily modifiable system, we decided on making a system based on a bunch of transforms childed to the player that would serve as the formation locations. The Leader script basically just grabs all of the children objects and holds them in an array. This is the formationPositions array. It then has a public static method that gives one of these gameObjects and then increments a counter so the next time it is called it returns the next one. This leads into the Follow script.

Follow Script

The Follow script is placed on the objects that will follow the player when collected. The first action is having them be collected in the first place. This is done with a simple collision that starts the following (and turns off the collider so they don’t interact with anything, including the player again). To help with the overall idea of being in formation, the Follow object actually grabs that next gameObject in the formationPositions array to follow around. This is how each object actually gets a different spot in the formation to follow around. With this setup, we just needed to determine how we wanted them to follow.

Various Follow Methods

First, I tried using a combination of LookAt and adding a velocity in the transform.forward direction. This was solid for giving them a bit of an organic movement feel, but it was not very controlled. If the speed was very different from that of the player, their movements felt awkward and they would also tend to clump up. This could be an interesting solution route, but it would take a lot more work to function properly.

Next, we looked at simply setting the transform.position to the follow object. This wasn’t great as it looked very mechanical, especially immediately upon collecting the object. It would just teleport behind the player.

Finally, we settled on using a Lerp function along with the transform.position. With use of an additional speed variable, this gave us a nice, smooth motion that was easy to modify to give various feels.

FormationNoise

After settling on the foundational movement for the following objects, we wanted to look into adding some noise to their movements to make them feel a bit more lifelike. Since I knew there were going to be a few different options of noise I’d like to switch between to see which ones felt better/worse with different parameters, I looked into setting up an enumerator with a switch case statement to easily switch between these different options. I simply created an enum called Motion that held a value for each of the different types of noise I made, and had a switch case check the Motion motion to determine which noise that specific object would use. This ended up being extra nice as I could also have different objects testing different types all at once.

It should also be noted that in order to keep things simple, I added the FormationNoise script directly to the formation position gameObjects that were childed to the player. Moving these simple transform objects would in turn move the following object following it as it is specifically given this gameObject transform to follow.

Finally, since everything was dealing with keeping these objects in the general area designated for their spot in a formation, the initialLocation is recorded on Start so we know its initial localPosition. This helped move the objects around this point, as opposed to continually adding or something and having it fly out of position.

Noise Methods

The first noise we tried was a simple random range applied to the entire position vector of this formation position object. I created a variable for the max and min of the random range to randomly sift through, and every frame a value in this range would be added to the initialLocation. This actually ended up being pretty nice for creating a “buzzing” or “vibrating” effect, which was nice since these would eventually be applied to bee characters for the ‘ project, but other than that it was not very interesting motion.

Since that method seemed a bit too hectic, I wanted to test just adding some noise to a single dimension. I chose the x-axis to randomize along since that seemed like it would give the most interesting results from my camera top view. This did seem a bit more controlled, but still mostly just had a “buzzing” feel to it.

Finally, I thought about what general motion I would like along with the noise and I thought a nice overall controlled swaying and/or bobbing would be nice to have with the noise. This method got a bit more involved. I created a sway variable, which would determine the amplitude they would drift on a given axis (for initial testing, I just did the x-axis). I also created a swaySpeed to determine just how fast they moved between the max and min sway locations.

Since I liked the “buzzing” feel of random moving the point around a small range, I kept that for the y-axis and z-axis. I just had the sway controlling the x-axis movement. This had the object buzz around a bit as it moved back and forth relative to its given initial formation position. This all led to a nice movement that was still very controlled, but felt a lot more alive.

POTENTIAL IMPROVEMENTS

The movement of the objects when they are following a significantly fast player still looks pretty direct and parented. It appears that if their overall speed is much greater than the movements/speed of their internal noise methods, the noise gets a bit lost or drowned out. This is something I will just have to player with more when dealing with the relative speed of the following objects and the player.

Possibly control more axes of noise a bit more. Adding a bobbing effect by swaying in the y-axis would give a nice effect. If we control too many axes, we’ll have to recheck if it’s still a nice effect or if we’ll need to add more actual noise to the movements again to keep them from feeling too robotic.

Currently the setup of the Leader’s formationPositions array only makes an array the size of how many children the player object has at startup. This makes the system a bit rigid, or require having a bunch of unneccessary children objects for a while with possible errors for large numbers of followers exceeding the array count. A more variable system might use a list instead of an array, or just a large array with some method that creates gameObjects as followers are gained to add to that array.

Starting with Unity Shader Graphs – Brackeys

May 12, 2019

Unity Shader Graphs

Basic Tutorials

Youtube – MY NEW FAVOURITE FEATURE! – Shader Graph Tutorial

By: Brackeys

Youtube – FORCE FIELD in Unity – SHADER GRAPH

By: Brackeys

These tutorials get into the basics of using the Shader Graph feature in Unity. This seems like a nice tool to have a basic understanding of to make some cool effects, so I want to check in on it at some point.

Dynamic Batching/GPU Instancing in Unity

May 7, 2019

Dynamic Batching/GPU Instancing

Following Tutorial

Youtube – [Unity] GPU Instancing Tutorial

By: Blendcraft Creations

In Unity, the benefits of GPU instancing may not be imediately noticeable by the FPS alone in the editor. This first tutorial shows that the FPS is more properly represented in an actual build of the project. Even though this is an older Unity version, that is still good to note to test all the way through to see if you are getting the expected results.

Following this tutorial appeared to work as intended, but it did have a weird issue where I couldn’t create lower numbers of instances of objects. Upon inspecting the script, I determined that any number below 1000 most likely would not be rendered out based on the for loop creating the batches at start. The following code snippet is where the issue was occurring:

private void Start()
{
int batchIndexNum = 0;
List currBatch = new List();

for (int i = 0; i < instances; i++)
{
AddObj(currBatch, i);
batchIndexNum++;
if(batchIndexNum >= 1000)
{
batches.Add(currBatch);
currBatch = BuildNewBatch();
batchIndexNum = 0;
}
}
}

I amended this with a quick fix using a small snippet after the entire for loop as follows:

if(batchIndexNum != 0)
{
batches.Add(currBatch);
batchIndexNum = 0;
}

This allowed me to now render numbers of instances less than 1000, and theoretically allowed me to render instances of any amount now, where initially it would only render multiples of 1000.

I would need to do further analysis to really understand the processing benefits of this, but it is a nice start to at least see that it is working and creating many instances of an object for me. I was safely able to create a few thousand instances of simple objects and run the game in the editor for what it’s worth. I also added a very basic 3D player controller that mostly moved the camera around to get a better idea of how everything was running with all of these objects created.

Look Into – Coding
  • Graphics.DrawMeshInstanced()
  • Operator: =>

Learning Scriptable Objects in Unity

May 6, 2019

Scriptable Objects in Unity

Basic Tutorials

Youtube – Unity3D – Using ScriptableObject for Data architecture / sharing

By: Unity3d College

Youtube – Introduction to Scriptable Objects – Unity 2018 Tutorial

By: Chris’ Tutorials

Youtube – How To Improve Your Game With Scriptable Objects – Unity

By: Dapper Dino – Coding Tutorials

I’m just saving some decent looking tutorials from starting with scriptable objects in Unity. These are something I still haven’t really gotten to in Unity, and I especially want to get a handle on them since they are apparently a useful tool in passing information between scenes using the new scene management approaches in Unity.

Pokemon in Unity – Tutorials

April 28, 2019

Making Pokemon in Unity Tutorials

Youtube – Lets Make… Pokemon in Unity! – Episode 1 – Basic Setup World/Character

By: BrainStorm Games

Youtube – Unity Lets Clone a Game [ Pokemon ] – Part 1

By: JesseEtzler

Going off of my recent trend, I’ve just been looking to grab tutorials to make games I loved (or still love) playing as a way to learn more about coding different systems in Unity with C#. I believe the Pokemon games will help get me into some scripts that are very repeatable on a large scale (such as a script that creates a pokemon and its stats), which is something I haven’t gotten into a lot.

Being an RPG game with random encounters, it may also help me work in a system that very consistently moves between two major scene types with the overworld scenes and the battle scenes. These scenes will also give the player very significantly different actions while still carrying information between the two types of scenes.

Ori and the Blind Forest: Building in Unity

April 27, 2019

Mimicing Ori in Unity

Bash Action

Youtube – Ori and the Blind Forest – Game Design Reel

By: James Benson

Youtube – Making Ori Y Bash [Unity C#] (Ori and the Blind Forest) #1

By: Wabble – Unity Tutorials

As a big Ori and the Blind Forest fan, I just wanted to see if I could find some tutorials to put together some of the movement or actions given to the player in Ori. The first video is a cool sample of a lot of the different game mechanics seen in Ori, as both their simple concept version as well as their in game version. This is actually extra helpful as the concept version really simplifies it down to what is really happening and makes it easier to process and disect to replicate.

GPU Instancing in Unity

April 25, 2019

GPU Instancing

Tutorials for Unity

Youtube – GPU Instancing Tutorial (No, Seriously, This Is Easy)

By: Craig Perko

Youtube – [Unity] GPU Instancing Tutorial

By: Blendcraft Creations

Youtube – Unity3D – 2 Minute Tips – Use GPU Instancing to reduce drawcalls when batching won’t

By: Unity3d College

Youtube – GPU Instancer – Features Showcase

By: GurBu Technologies

I am starting a project in class that is potentially looking to instantiate a lot of flower objects in Unity, so I wanted to take a look at GPU instancing and see if this was a practical solution for us if we ended up going down this route. If not, this is still a good opportunity for me to get a taste of working on purposefully passing certain information to the GPU and using it for specific tasks.

The first three videos are direct tutorials showing how to set this up or how to use it, while the last one is an already made asset in the Unity Asset Store showcasing a very strong GPU Instancing heavy asset and some of its capabilities. I think the final one is nice to have to at least show some of the more interesting capabilities this can lead to.

Tower Defense Scene Management Issues

April 25, 2019

Scene Management Solutions

Identifying Issues and Possible Solutions

Scene Conflict
  • There are two scenes that load at the same time that have scripts within them that want to reference scripts within the other or both reference the Logic scene which needs to be updated simultaneously
  • Even though they should ideally be loading at the same time, one is always loading ‘just before the other’
  • This causes the first scene loading to miss its references since the other scene does not exist to it yet when it goes to get those references
  • The second scene loading in does however load its references properly
  • I’ve tested switching the order of loading and the second scene functions properly consistently, while the first scene has errors
Current Issues
  • Level scene loading second to make sure the nodes can get the BuildManager reference
  • However, the Level scene sets the number of lives the player has (LevelPlayerStats passes lives in to the PlayerStats script in the Logic scene)
  • The LevelManager in the Base scene checks the player lives to see if it should end the game
  • Since the Base scene is loading first, it checks and sees there are 0 lives before LevelPlayerStats can set the correct amount of lives for the level
  • This is setting the game to Game Over immediately
Proposed Solutions

Find way to time events: Setup the scene manager system in a way that it makes sure everything is loaded before attempting to setup references. Functionality of the game also needs to wait some time to make sure the newly loaded scenes have time to set the values necessary in the Logic scene before actually starting so they don’t try to work with default values instead.

Move references: Currently the issue is that no matter which scene loads first, there are reference timing issues with one of them. This could be evaded by placing all of the references that should be done first into the same scene and just making sure that scene loads first.

I believe the timing control solution is the better and more powerful solution, as this will help anytime I really need to have multiple interscene references in the future. That is also the much more difficult solution though. I may go with the simpler solution for now just so I can continue experimenting with the more game design heavy concepts of working on the tower defense game and then come back to figure out the stronger solution later.