Unity Fixed Update Purpose

September 25, 2020

Unity

Fixed Update


Title: GameDev Stream — What is FixedUpdate For?
By: Infallible Code
Youtube – Information
Description: Quick rundown of the main purpose of using fixed update in Unity.


Overview

This video quickly covers the main purpose of using FixedUpdate in Unity. As most Unity users know this is commonly used for containing physics calculations, but they better describe why that is here. They explain that FixedUpdate is much more consistent as it is inherently time based, whereas Update is tied directly to frame rate, which can vary drastically from computer to computer or user to user. This consistency however is what also makes FixedUpdate bad for uses such as user input because they could basically be entering inputs between the FixedUpdates and they will not be picked up at all, which is obviously extremely bad.

Unity Scriptable Objects Tutorial Updated

September 24, 2020

Unity

Scriptable Objects


Title: Better Data with Scriptable Objects in Unity! (Tutorial)
By: Unity
Youtube – Tutorial
Description: Quick updated rundown by Unity themselves on using Scriptable Objects.


Title: Scriptable Object Unity Documentation
By: Unity
Unity – Documentation
Description: One of the suggested links to follow from the tutorial video that is just the official documentation on scriptable objects.


Title: Making cool stuff with ScriptableObjects
By: Matt Schell
Unity – Blog
Description: Another suggested link to follow from the tutorial video showing some more examples of using scriptable objects.


Overview

I wanted to make a quick reference to this new video as it was just released yesterday (Sep 23, 2020) and I have wanted to explore scriptable objects in Unity and getting recently updated information is always useful.

Scriptable Objects as Data Containers

Scriptable Objects can be useful tools as data containers as is shown in their example using them for cards in a card game. They explain they can be a better option here than a Monobehaviour because Monobehaviours must be attached to a gameobject, where as Scriptable Objects can be used similarly to regular objects in that they do not have this requirement. If data does not belong to an instance, but is more shared amongst game objects, it is better to store it in a scriptable object. This is because when Monobehaviours reference Scriptable Objects they store a reference that points to the scriptable object as opposed to making their own copy of the data.

Scriptable Objects as Enum States

Scriptable Objects can also be used to author extended Enum states. They explain this through an example where they have a Placeable Data scriptable object which has Enum options for their Attack Type and their Target Type. This appears to just mean they support Enum lists which then allow for an easy dropdown option in the Inspector (similar to how Enums generally work in my experience).

Runtime Data Editing

They expand on the benefits of using scriptable objects as extended Enum states is that they allow for real time data editing (while in play mode). Normally most edits made in the Unity Editor during play mode are not saved so you have to remember them and reapply them if they are changes you want. Scriptable objects however can have their edits during play mode saved on the spot so they will persist even after leaving play mode. This is because scriptable objects are not bound to a scene’s runtime, they exist on a project basis in the Assets folder.

Reference List for Creating State Machines in Unity with Focus on Character Controllers

September 23, 2020

State Machines

Unity and Character Controller Focus


Title: The State Pattern (C# and Unity) – Finite State Machine
By: One Wheel Studio
Youtube – Tutorial #1


Title: How to Code a Simple State Machine (Unity Tutorial)
By: Infallible Code
Youtube – Tutorial #2


Title: Complex Enemy Behavior using Finite State Machines – 2D Platformer – Part 13 [unity]
By: Bardent
Youtube – Tutorial #3


Title: State Machine Setup – 2D Platformer Player Controller – Part 21
By: Bardent
Youtube – Tutorial #4


Title: Movement State Machine – Free download
By: Epitome
Youtube – Tutorial #5


Title: Unite 2015 – Applied Mecanim : Character Animation and Combat State Machines
By: Unity – Aaron Horne
Youtube – Tutorial #6


Overview

I have dealt with using state machines before, but mostly for creating AI systems. I wanted to investigate using a state machine specifically for a player controller, focused on 2D player controllers if possible. With this in mind, I just gathered many resources on more general state machine concepts and design with a mix of more player controller focused examples when possible.

The quick breakdown is as follows:

  1. Tutorial #1 – General Finite State Machines
  2. Tutorial #2 – General Finite State Machines
  3. Tutorial #3 – AI Finite State Machines
  4. Tutorial #4 – Player Controller Finite State Machines
  5. Tutorial #5 – Player Controller Finite State Machines
  6. Tutorial #6 – Player Controller/General Finite State Machines

Tutorial #1

This is a great quick tutorial on Finite State Machines and implementing them in general in C# and Unity. It covers the various levels of state machine implementations and the pros/cons of each tier of state machine organization. This is a fantastic starting point for state machines.

Tutorial #2

This tutorial is a more general state machine but it does still have a focus on turn based gameplay. While I was focused on player controller FSMs, I am also interested in how to use these for game states in turn based play so I wanted to record this.

Tutorial #3

This tutorial focuses more on AI FSMs, which I have more experience with, but I still wanted to grab a reference to this as a decent looking tutorial on implementing an FSM in general. I also have another Bardent tutorial that is a player controller focused FSM so I thought this also might help me tie in my prior experience if I followed this approach.

Tutorial #4

As mentioned above, I have two tutorials from the same tutorial set and this is the second. I am hoping there is an overlap in the two systems that I can also take away from by observing what they are able to recycle between them. I also hope this will help make this FSM make more sense since I can tie in my prior AI FSM experience.

Tutorial #5

This is a quick tutorial that directly shows the setup for a player controller FSM. It appears that it might not be the ideal architecture I am looking for, but it could still serve as a good example when starting to design a player controller FSM.

Tutorial #6

This older (from 2015) Unite talk goes a bit more in depth into the combination of character animation and combat state machines. This could be a strong next step for me to look into after focusing on movement for the core of the player controller state machine. I am especially interested in seeing if I can implement their combat combos with their FSM approach in some capacity, as well as if they have an input buffering design I can learn from.

2D Melee Combat Tutorial and Game Kit with Thomas Brush

September 22, 2020

Game Development

2D Melee Combat

How To Make 2D MELEE COMBAT (Unity Tutorial + Free Game Kit!)

Youtube – Link

By: Thomas Brush


Referenced Previous Tutorial
How To Make 2D Platformers (Unity Fundamentals Tutorial)

Youtube – Link

By: Thomas Brush


First Portion

Camera

They start by using a VirtualCamera game object from the Cinemachine package within Unity. This camera object gives a lot of useful camera controls without having to build another from scratch. They mention another tutorial to help with paralaxing, so this may not be included in the virtual camera.

Character Animation

Spine

This seems to be the major animator they used, so this may be something worth looking into as I have come across it a lot now. For animation tips, they suggest strong bouncing effects on the vertical axis (squashing and stretching majorly in the y-axis generally, with some distortion in the other axis). Spine also gives you the option of different skins to provide the same set of animations to similar character type objects.

Animation State Machine

Again they reference a previous tutorial covering this more in depth. They do show how their animation system fires events to help perform certain actions in tandem with the animations without necessarily adding more programming. Examples for this include emitting particles or playing a sound on animation start or end.

Making Fighting Games in Unity

September 18, 2020

Unity

Fighting Games

Create A 3D Fight Game In Unity In One Video | 3D Beat Em Up Unity Tutorial | Fight Game Unity3D

Youtube – Link

By: Awesome Tuts


Hitboxes (Fighter Melee Attack) – Game Mechanics – Unity 3D

Youtube – Link

By: N3K EN


Overview

There is some significant overlap with fighting games and beat ’em ups when it comes to general combat in any 2D platforming game, so it made sense to look to these sources for more inspiration and options for designing a combat system within such a game. Using a fighting game frame system with start up, active, and recovery frames can also be tailored to work with general combat systems, so when looking to be flexible it makes sense to use a system like this that is applicable to many cases.

Neither of these examples specifically get into a specifically frame driven system, but they at least show the basics of tying animations into actions and hitboxes more, as well as exploring combos and possibly input buffering more as well. These options at least help expand some of the more basic combat options I have seen in more platforming focused 2D sources.

Unity Learn Class – Unity Gameplay Programming Fundamentals

September 14, 2020

Unity Learn

Gameplay Programming Fundamentals

Unity Gameplay Programming Fundamentals

Unity Learn – Link

By: Joshua Kinney


Overview

This is just a more advanced Unity programming fundamentals class, which sounds like exactly what I am looking to shore up currently, especially going into another personal project. This even has a focus on player movement scripts and interactive objects, which will fit very nicely with the next project I am looking to work on.

Using Unity Events and Events and Deciding Between Them

September 7, 2020

Unity

Events and Unity Events

Events or UnityEvents?????????

Youtube – Link

By: Jason Weimann


Overview

Events are something I want to utilize more consistently and more effectively in my code setups, so this seemed like a good supporting block to look into to understand their usage better. It also covers the usage and differences between Unity Events and the standard C# Events, so this gives me more options to explore and utilize as well more so than some other sources.

Continuing 2D Melee Combat Research for Unity

September 4, 2020

Unity

2D Melee Combat

Easy 2D Melee Combo System in Unity: Tutorial

Youtube – Source #1

By: ChosenPlay


2D Game Dev Tutorial – Melee Attacking in Unity (Sprites included)

Youtube – Source #2

By: Lost Relic Games


Basic Combat – 2D Platformer Player Controller – Part 9 [Unity 2019.2.0f1]

Youtube – Source #3

By: Bardent


Overview

After finding a decent basic starting point for 2D melee combat in Unity, I wanted to find a few more sources and options to support and develop that further. These sources I found look more into the animation options a lot, as well as some minimal input buffering as well as chaining/comboing, hitbox activation, and state machine implementation.

Source #1

Source #1 uses some transition animations to provide an example how to nicely transfer between various action animations when allowing characters to combo. This option also shows some minimal state machine usage (which seems like a strong candidate as a foundation for these character controllers).

Source #2

Source #2 delves into a large chunk of setting up a character controller with a focus on the melee combat. It explores the animation setup as well as an in depth showing of the programming behind everything. This includes basic character controller work as well as how to perform the combat input and hitbox activation. Most control is done directly through the Update methods here so it works better as a learning tool than a foundation for a proper system.

Source #3

Source #3 is another very basic option that is also in a tutorial set, so it will most likely provide the least information but could still give some helpful options. Being part of a tutorial set also helps me keep track of the entire set in case I wanted to follow it more before or after this specific tutorial.

Unity Melee Combat Basics with Brackeys Tutorial

September 3, 2020

Unity 2019

Melee Combat

MELEE COMBAT in Unity

Youtube – Link

By: Brackeys


Summary

I want to explore making 2D character controllers, so looking to add melee combat as an option is a very common addition that I want to understand better. Being a Brackeys tutorial this is a rather basic approach with very Unity specific options, but it at least provides a good starting point to get something up and running. I would like to look into other options to add to this so I know a few ways to add hitbox generation nicely to characters and agents alike.

UnityLearn – AI For Beginners – GOAP – Adding Goal Challenge & Taking a Break

August 19, 2020

AI For Beginners

Goal Orientated Action Planning (GOAP)

Parts 14 and 15


Beginner Programming: Unity Game Dev Courses

Unity Learn Course – AI For Beginners

Adding Goal Challenge

Adding Goal Challenge

My Approach

This tutorial starts with another challenge to implement a new GAction. This time it is the GoHome GAction for the patient to return to a transform tagged “Home” after they receive treatment. This was rather straight forward as I created this new GAction that just had a Preperform method setting the target to the tagged gameobject “Home” and putting in the Postperform method that the TreatingPatient world state should be reduced by 1 (since they have finished being treated).

Once this GAction was applied to the patient, it needed to connect to the previous action by having a precondition of “isTreated” and I added an after effect of “isCured”. The “isCured” state was also added as the new secondary subgoal of the patient GAgent to ensure they would move entirely through the chain of actions. I did initially just add “isCured” as a 3rd goal (keeping the 2nd goal of “isTreated”) but this created a strange behavior where the agent would take one extra step of actions and return to the hospital entrance after returning home.

Their Approach

They named their new subgoal “isHome”, which I think is important to note because I think with a system like GOAP you should keep in mind that the actions should be somewhat isolated for their specific purpose and you should at least be cognizant of chaining the actions together too much for what you think their intended purpose may be and recognizing when to keep them more encapsulated as their own action. It makes sense that the patient’s true goal is just “to get home” and getting cured of their ailments is just an obvious way to us to achieve that goal given the settings, but being cured is just a major step towards simply getting home.

They also added an extra step of states for the patient agent. I simply connected the previous action to the new action by matching the GoHome action’s precondition with the GetTreated after effects (“isTreated”), but they actually had the GetTreated action modify the state of the agent to add “isCured” and used this (“isCured”) as the precondition for their GoHome action.

While this does not seem necessary in the current state of the tutorial, I think this makes sense to add this step when developing a real GOAP system because there could be several ways for a patient to be cured (such as simply waiting it out if it is a minor ailment like a cold). So this approach may make more sense when building a proper system, which again, is good to note for the future if building a system like this for your own project.

I ran into an issue where the patient agent was not leaving the waiting room, and it turned out this was because I still had the “isTreated” intermediate subgoal commented out because it was necessary for my approach to work. Adding this subgoal back in (along with the additional “isHome” goal) allowed the agent to work properly again.

Errors

They ran into a problem with the tutorial (that I also replicated) when they turned the spawner back on to add many patients to the system. Many of them began congregating at the hospital entrance, which was due to the fact that “isTreated” was one of their subgoals and it was being immediately met because the first patient treated added “isTreated” to the entire world state so every patient thought it was already treated.

This led to them pointing out a rule of thumb where you do not want any of the subgoals of the agents to match a state that is directly added to the world state or the agent’s beliefs. So to follow this up, I changed the world state modification within the GetTreated action from “isTreated” to just “Treated” (this appears to be what they did in the tutorial but it is not clearly stated).

While fixing this, they also note a possible issue with the NavMesh system in Unity. Something about the NavMesh that even when it gets a path it thinks the destination was the previous destination, so it returns that the path was “completed” before the agent actually gets there. This can cause agents to start on the next action since many are location based. This was clarified to possibly be a result of their large update method within GAgent that is using NavMesh’s SetDestination method. They suggest that the loop may be processing through again before the SetDestination has been fulfilled which can cause issues.

Distance Check

To solve this issue they decide to just have their own distance check for destinations. For this they just did a basic distance check between the agent’s position and its destination position.

Speeding Up the System

To help with the debugging process they simply sped up the entire game system. This can be done very easily by just setting Time.timescale to a value greater than 1.0 anywhere in your scripts. This is actually very handy to know and would be an insanely useful tool moving forward to add to a major static debugging script for any project that could be toggled and edited to help with various debugging processes (i.e. they just added that line to the GWorld class since it’s a systematic static class).

With all of these fixes and modifications in place, the system now appears to run rather smoothly and appropriately. It was working so well I tested adding another nurse agent to see how it would adapt and it continued to work flawlessly. The new nurse would properly grab patients that the other nurse was not treating and take them to a different cubicle to treat them, so there was no strange noticeable overlap of actions.

Taking a Break

Taking a Break

This tutorial looks at adding a Rest action to the nurses so they will sometimes take a break and move to the lounge area to regain energy to continue working. To begin, they added a small method within the nurse GAgent class to modify their beliefs every so often to add the exhausted state to them. This gets the exhausted state into the overall system to help start allowing it to control their actions.

They then added the new action named Rest which simply has a Postperform method for removing the exhaust state. This paired with adding a duration to this action is all that is necessary to provide a timed cool down for the nurse to remain out of commission for a time before coming back to action rested.

How they set it up the nurse agent’s are only able to rest if there is time (so either there are no patients or no available cubicles). So when there is only a single nurse and a lot of patients, the rest action is never seen. To show it working, they added several nurses (about 5) to the system. Once this was done, it could be seen that occasionally when a nurse was finished treating a patient they would go to the lounge area instead of directly to another patient. They would then come out of the lounge to grab a patient after being rested and having another action to perform.

Finally, they added the removal of the patient agents once they returned home just to keep the system cleaner. This was very simple as they just added Destroy(this.gameobject) to the Postperform method of the GoHome action.

The following is a quick link showing my finished GOAP tutorial project in action
Link to Video of My Completed GOAP Tutorial in Action

Summary

This overall tutorial was amazing for introducing me to a new AI system. I still need to look over some of the foundational interactions of the major classes, but I understand the system from a conceptual view pretty well now and it seems very useful as another AI option depending on your case.

The next to last class (Adding Goal Challenge) was very useful for understanding some of the issues you can run into and how to ensure the system runs smoothly and controlled. Understanding keeping the states very separated between the different actions/agents and the overall world state is crucial to make sure you do not get some nasty bugs. Then the speed up feature available in Unity is definitely something I need to take more advantage of when debugging in particular.