Posts

Showing posts with the label UnityLearn

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.

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 sec...

UnityLearn - AI For Beginners - GOAP - Implementing the Inventory System & Moving the Nurse

August 13, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Parts 12 and 13 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Implementing the Inventory System Implementing the Inventory System They begin this tutorial by adding another simple GAction to the patient agents named GetTreated. They follow this up by adding a WorldStates object to the GAgent class (named beliefs) as well as a WorldStates object in GAction that references the GAgent's beliefs (similar to how the GInventory reference was passed between GAgent and GAction). They then add some logic to the GAction GoToWaitingRoom to add the atHospital state to the beliefs of the GAction itself. Upon running it there is an error because the GPlanner has not been built to handle beliefs (the internal WorldStates of the GActions or GAgents). To solve this, they add a Node overload constructor to the GPlanner class to also take in a WorldStates reference to acce...

UnityLearn - AI For Beginners - GOAP - Adding More Resources to the World

August 10, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Part 11 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Adding More Resources to the World Adding More Resources to the World The next step is setting up the use of the cubicles in the world. Similarly to patients, these cubicles act as a resource available to the agents. Therefore they must be monitored by the world state in some way to determine how many are available and which ones so they can be distributed properly when needed. Setting this up was very similar to how the patient resources were. They added a queue of gameobjects to hold the cubicles in the GWorld class. This was a bit different as it also initialized full of resources, so the cubicles were immediately added to this queue (through FindGameObjectsWithTag) upon initialization. Then again similar to patients (except through the GWorld class itself instead of an action) a state was added to the...

UnityLearn - AI For Beginners - GOAP - Creating a Multi-Step Plan & Plans That Require Multiple Agents

Image
July 30, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Parts 9 and 10 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Creating a Multi-Step Plan Creating a Multi-Step Plan This tutorial begins linking multiple actions together to create more intricate action plans. To do so, they created a second GAction, GoToWaitingRoom. GoToHospital action was given an after effect of hasArrived and GoToWaitingRoom was given a precondition of hasArrived to give them a point to link together. GoToWaitingRoom was then given the after effect isWaiting, so that the goal given would match up with this second action's outcome. This let's the system take an input goal of isWaiting and deduce the plan of action to get there through these two actions. Just to better visualize this demonstration, they created a basic spawner to consistently spawn in new patients to show that the newly created objects can follow the plans created prop...

UnityLearn - AI For Beginners - GOAP - Executing a Simple Plan

July 21, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Part 8 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Executing a Simple Plan Executing a Simple Plan This tutorial starts by actually implementing the newly created planner setup within the agents themselves. This involves creating a rather bulky LateUpdate method within the GAgents class which tries to handle all the possible cases of different states of having a planner and having actions to perform. This LateUpdate can be broken down into four main sections: Continues running an action that is in progress Generates a plan and possibly an action queue if they are not already present in agent Removes goal and planner once entire action queue is used up Selects the next action in queue to start performing They then created a new Patient class (which inherited from GAgent) to place on the patient agents and they created a new GoToHospital class (which i...

UnityLearn - AI For Beginners - GOAP - The GOAP Planner

July 21, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Part 7 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners The GOAP Planner GOAP Planner - Part 1 Planner starts by looking through all the achievable actions and finding which can be performed given the starting states from the first node. This can create the branches for the action network which will then continue to have actions connected to them (that satisfy the state conditions) until a chain is found that has a result which matches the initial goal. GPlanner Class The first major step of this class is creating the Plan method which returns a Queue of GActions (this will basically be the full list of actions that will be chosen to actual be acted out). This starts by making a List of usable GActions (those which satisfy the IsAhchieavable condition). They then start a List of the newly create Node class objects, which acts as a more encompassing container f...

UnityLearn - AI For Beginners - GOAP - Setting Up GOAP System

June 11, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Parts 4, 5, and 6 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro This part of the course gets into actually programming the GOAP system and using it within their example Unity project. These tutorials focused on setting up the foundational classes: GAgent, GAction, GWorld, and WorldStates. These are used as the core of the system as they either hold all the information to pass around through the system, or serve as the base classes to work with for creating agents within the system. The World States The World States The main scripts created here are: GAgent GAction GWorld WorldStates WorldStates: They added another class within this script named WorldState. This WorldState class just holds a string named key, and an int named value. These will be used for a dictionary setup, hence the key and value naming setup. The rest of the WorldStates class i...

UnityLearn - AI For Beginners - GOAP - Introduction to GOAP

June 10, 2020 AI For Beginners Goal Orientated Action Planning (GOAP) Parts 1, 2, and 3 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro This course covers goal orientated action planning (GOAP) as another way to set up flexible systems of AI behavior. This blog covers the first 3 tutorials of the course which introduce the general GOAP concept by defining its parts and explaining the planning process going in to creating a GOAP system. An Introduction to GOAP GOAP Introduction Goal Orientated Action Planning (GOAP): has all the elements of a finite state machine, but uses them differently uses graphs for processing GOAPs actions and goals are decoupled actions are free elements in the system that are mixed/matched to meet goals instead of having a list of actions needed to meet a goal, GOAP allows for multiple solutions to be chosen from Actions Components: Precondition, Effect Precondition: state that must be met...

UnityLearn - AI For Beginners - Crowd Simulations - Flocking

May 22, 2020 AI For Beginners Crowd Simulations Part 3 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro This was by far the most interesting crowd simulation tutorial covered in the basic AI tutorials. This one really got into an actual rule based logic system for pathing of agents within a large group to move them in an interesting way with emergent behavior that is still controlled and possible to direct. Flocking Part 1 Flocking: simple rules to generate movement for groups of individuals to move towards common goals (i.e. birds or fish) They create a FlockManager because flock movement requires the individual agents to know about and understand they movement and positioning of all the other agents around them. This will be at a higher level providing data for an entire flock as a whole. This starts with logic to instantiate the flock by creating many fish prefabs in a randomized starting position bound around the FlockMa...

UnityLearn - AI For Beginners - Crowd Simulations - Fleeing

May 22, 2020 AI For Beginners Crowd Simulations Part 2 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro I was going to combine both of the end parts of the Crowd Simulation tutorial into one blog, but the Flocking tutorial was rather large and interesting so I decided to break it off into its own post. Because of that, this is a smaller one just focused on the basic fleeing crowd logic. Fleeing This is similar to the concept covered with single AI agents, it is just being applied to many agents here. An object is introduced to the environment and the fleeing agents determine the vector towards that object, and set a new course for the exact opposite of that vector. Key Parameters covered for their flee inducing object: Radius of Influence - how close agents must be to be affected by the object Cooldown - how long an agent flees before returning to standard behavior They decided to induce fleeing by adding a cylinder obje...

UnityLearn - AI For Beginners - Crowd Simulations - Moving As One & Creating A City Crowd

May 20, 2020 AI For Beginners Crowd Simulations Part 1 Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro This is the first part of the Crowd Simulations section of the AI course that I covered. This was the first two major tutorials of four, Moving As One & Creating a City Crowd. These introduce the basic concepts of crowd simulations, and at least cover ways to start moving groups of agents with Nav Mesh Agents in Unity to help visualize these concepts (more so than particularly creating agent crowd AI behaviors yourself). 1: Moving As One Crowd Behavior: agents move enmasse, as opposed to solely as individual units; their movements are usually also dependent on each other's movements Reynold's Flocking Algorithm: Common flocking logic based on 3 simple rules: Turn towards average heading of group Turn towards average center of the group Avoid those around you They start with a really basic Nav Mesh setup...

UnityLearn - AI For Beginners - Autonomously Moving Agents

May 13, 2020 AI For Beginners Autonomously Moving Agents *Full Course* Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Intro I completed the full course for Autonomously Moving Agents within the AI Unity Learn course and am just covering it all in this blog post. I broke each individual tutorial into its own section. 1: Seek and Flee They start a new project and scene with this project where there is a robber (NPC) and a cop (player controlled), and the robber will be given logic to satisfy seeking and fleeing in relation to the player and the terrain obstacles. Seek: Follow something else around Flee: Move away from a specific object Seek follows logic they have already used for following an object. Using the difference in positions between two objects, you can generate a vector which gives the direction between them and use that to guide an object towards the other one. Similar logic is actually used for Flee, except they ju...

UnityLearn - AI For Beginners - Finite State Machines - Pt.02 - Finite State Machine Challenge

April 6, 2020 AI For Beginners Finite State Machines Finite State Machines Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Finite State Machine Challenge This tutorial provided a challenge to complete and then provided a solution. The challenge was to create a state where the npc would retreat to an object tagged as "Safe" when the player approached the NPC closely from behind. My Approach Since they had a State enum named Sleep already that we had not worked with yet, I used that as the name of this new state (I started with Retreat, but then found the extra Sleep enum so I changed to that since I assumed it would be more consistent with the tutorial). Similar to the CanSeePlayer bool method added to the base State class for detecting when the player is in front of the NPC, I added an IsFlanked bool method here that worked similarly, but just detected if the player was very close behind instead of in front. I used this ...

UnityLearn - AI For Beginners - Finite State Machines - Pt.01 - Finite State Machines

April 1, 2020 AI For Beginners Finite State Machines Finite State Machines Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Finite State Machines Finite State Machine (FSM): conceptual machine that can be in exactly one of any number of states at any given time. Represented by a graph where nodes are the states, and the paths between them are the transitions from one state to another. An NPC will stay in one state until a condition is met which changes it to another state. Each state has 3 core methods: Enter, Update, Exit Enter: runs as soon as the state is transitioned to Update: is the continuous logic run while in this state Exit: run at the moment before the NPC moves on to the next state State Machine Template Code (Can use core of this for each individual state): public class State { public enum STATE { IDLE, PATROL, PURSUE, ATTACK, SLEEP }; public enum EVENT { ENTER, UPDATE, EXIT }; public STA...

UnityLearn - AI For Beginners - Navigation Meshes - Pt.02 - Navigation Meshes

March 30, 2020 AI For Beginners Navigation Meshes Navigation Meshes Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Navigation Mesh Introduction Nav Mesh: Unity function for making a navigable area for agents to traverse over. There are 4 main tabs in the Navigation window: Agents Area Bake Object Agents Core Parameters: Radius, Height, Step Height, Max Slope These dimensions determine where the agent can fit when navigating around obstacles, as well as how it can traverse elevation differences. Radius and height help limit where a character can go (cannot go between very small gaps or under objects very close to the ground) where step height is the elevation difference it can traverse in a single jump and max slope is how inclined the surface can be for the agent to travel on. The name allows you to save several types of agents, with various values for these 4 core parameters. Area How you define different costs for diffe...

UnityLearn - AI For Beginners - Waypoints and Graphs - Pt.01 - Graph Theory

March 24, 2020 AI For Beginners Graph Theory Graph Theory Beginner Programming: Unity Game Dev Courses Unity Learn Course - AI For Beginners Graph Theory Intro The AI for Beginners course starts very basic so I have not covered a lot up until now. It handles the basics of moving an object with simple scripting, as well as guiding and aiming that movement a bit. This section starts to get into some more interesting theory and background for AI. Graphs are simply collections of nodes and edges. Nodes are locations or points of data, and edges are the paths connecting them (which also contain significant data themselves). There are two directional types for edges within these graphs: directed and undirected. Directed paths only allow for movement between two nodes in a single direction, while undirected paths allow for movement either direction between nodes. Graphs are used in any case to move between states. These states can be real states or conceptual states, so the...

UnityLearn - AI for Beginners - The Mathematics of AI - Pt. 01 - Cartesian Coordinates

March 6, 2020 AI for Beginners The Mathematics of AI Cartesian Coordinates Artificial Intelligence for Beginners Unity Learn Course - AI for Beginners Cartesian Coordinates Cartesian Plane Cartesian coordinates: used to determine locations in space for any number of dimensions generally used for 2D and 3D space in games (x, y) and (x, y, z) 2 Main Projection Types: Orthographic and Perspective Orthographic: 3D space represented by a cube or rectangular prism Perspective: 3D space that looks like a rectangular pyramid with its top cut off The Camera size in Unity when using the Orthographic perspective dictates how far the camera sees for the smaller dimension of the aspect ratio. It is the number of units in both the positive and negative direction away from the origin the camera sees, so the smaller dimension of the aspect ratio is double that of the Size value given to the camera. The larger dimension in the aspect ratio is then the ratio multiplied by tha...

UnityLearn - Beginner Programming - Creating a Character Stat System - Pt. 05 - Accessing Variables in Our System Part 2 (End of Course)

March 6, 2020 Beginner Programming Creating a Character Stat System Accessing Variables in Our System Part 2 Beginner Programming: Unity Game Dev Courses Unity Learn Course - Beginner Programming Accessing Variables in Our System Part 2 Leveling Up They created a LevelUp method within the CharacterStats_SO scriptable object. This accesses the leveling array they created earlier and sets all of the max stat values to those designated in the array for that corresponding level (each level is its own individual array element holding an entire list of all the stats and what they should be set to at that level). Configuring Your Systems They added the CharacterStats script to the main Hero character. They created empty gameobjects within the Hero character gameobject hierarchy for the character inventory and the character weapon. They then applied this to the base prefab (to make sure it wasn't only on a newly created variant of the prefab). They created a method nam...

UnityLearn - Beginner Programming - Creating a Character Stat System - Pt. 04 - Accessing Variables in Our System Part 2

March 5, 2020 Beginner Programming Creating a Character Stat System Accessing Variables in Our System Part 2 Beginner Programming: Unity Game Dev Courses Unity Learn Course - Beginner Programming Accessing Variables in Our System Part 2 Writing Your Character Stats MonoBehaviour They simply created the base CharacterStats class (non-scriptable object version). They gave it a constructor that created a reference to the CharacterInventory and had a Start method which initialized all the stat variables automatically if the "setManually" option was not checked. Using Your Scriptable Objects Methods They begin to fill the CharacterStats class they just created with many methods that simply call methods from the referenced CharacterStats_SO scriptable object. Here they also use the UnEquipWeapon method, which has a return type of bool. They use it in the ChangeWeapon method, and have it in the if statement condition. This is interesting as the method here will r...