Dev Blog

HFFWS Working with the Rope Script

October 23, 2019

Human Fall Flat Workshop

Rope Script

Identifying Key Components

The main components of controllilng the rope script when it comes to placing it and connecting it with objects, are the handles and the start/end bodies. The handles are transform positions that dictate key points on the rope. Two is the standard, as they determine a beginning and the end for the rope, but more can be used to direct the rope in multiple directions. The start and end bodies are rigid body references which determine objects that will be physically connected to the ends of the rope.

The discovery with how the handles work opens the possibility for more rope configurations other than flat ropes which fall over other objects. Being able to guide a rope around in interesting patterns could potentially allow for setups that are more similar to actual pulley setups, where a rope needs to go around a wheel object at least once.

The first prefab I worked with that used the Rope script had rigid body objects with Fixed Joints on them that seemed necessary at first. While working with another rope using prefab (the hook), I found that it did not use these Fixed Joints. This showed that these are actually not manditory for connecting rigid bodies to the rope. It is just the rigid body reference on the Rope script itself for the startBody and endBody. Further investigation may show what purpose the Fixed Joints served.

UnityLearn – Beginner Programming – Working with Classes – Pt. 03

October 22, 2019

Beginner Programming: Unity Game Dev Courses

Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Working with Classes

The Four Pillars of OOP
  • 1. Encapsulation: grouping of data and methods into a cohesive object
  • 2. Abstraction: process of exposing only those features of an object necessary for interactions
  • 3. Inheritance: creating a new class based on and extending another
  • 4. Polymorphism: ability of an object of function to take on a different form

The PlayerController class created for this section of the tutorials dervied from the Shape class, which allowed it to inherit the SetColor method and change the player to yellow. It also extended the class by creating its own method, MovePlayer. I am trying to keep track of this to ensure I keep all the terminology straight.

There was an interesting approach to using WaitForSeconds in the enemy spawning method. Instead of directly using new WaitForSeconds directly in the yield return statement of the coroutine, they actually created a WaitForSeconds variable reference named wait. They then just used wait in the yield return statement in place of all the WaitForSeconds syntax. This is nice to keep in mind as another way to organize coroutines, especially those that use similar values for multiple yield statements.

Inheritance and Polymorphism

Inheritance was demonstrated by creating protected variables within the base class that could be used by all of the derived classes. The examples here were halfHeight and halfWidth, which assumed the values of the bounds.extents of the SpriteRenderer at Start. This was done in the Start method of the base class, so the derived classes simply had to call base.Start() to have those values individually set for all of them inheriting from Shape class.

It is important to note for this to work they made the Start method in the base class a virtual protected method. This allowed the derived classes to override the Start method to add functionality, while also using the base.Start() method still to assume the base class’s Start method functionality. This started to get into polymorphism.

virtual: this keyword can be used to modify a method, property, indexer, or event declaration and allow for it to be overridden in a derived class

IMPORTANT: This can be used in conjunction with the protected access modifier to allow for a base class’s Start method to be useable within the Start method of derived classes. By creating a protected virtual void Start method in the base class, the derived classes can have their own modified Start methods by using a protected override void Start method and calling the base.Start() method from within.

Unity Procedural Landmass Generation by Sebastian Lague

October 21, 2019

Procedural Terrain Generation

Tutorial

Procedural Landmass Generation (E01: Introduction)

Tutorial #1 – Link

By: Sebastian Lague


This is the beginning of a procedural landmass tutorial by Sebastian Lague. This appears to get move involved in setting up noise with more controlled variability along with shading and other interesting tricks. This will compliment a procedural terrain tutorial I followed by Brackeys since this gets much more involved and gives many more designer options.

Thesis Puzzle Generation – Pulley Information and Variations

October 17, 2019

Thesis Puzzle Generation

Pulley Variants

Pulley Wikipedia Page

Info #1 – Link

By: Wikipedia


Pulley

General

The wikipedia definition of a pulley is:
“a wheel on an axle or shaft that is designed to support movement and change of direction of a taut cable or belt, or transfer of power between the shaft and cable or belt”
The pulleys we will be generating are generally simpler setups. They mostly consist of a rope with a physics object (rigid body) on each end. This is because of how the system is used to create the pulleys. Ropes cannot be intertwined between objects accurately, so they are just generated above their setup locations and allowed to fall into position. As a final note, the pulley can also be tied into demonstrating the wheel and axle simple machine as well.

Varieties

Hook on an end to latch onto other objects

This focuses on the pulley’s inherent nature of changing the direction of force. The hooks allow the player to attach one end to various objects to move them into place. It could also be as simple as lifting other objects.

Object to move can be used as a platform
Focus on rotation of wheel

This would use the weight/friction of rope to rotate/spin the wheel that it is on while rope is moved. I am not sure how well the HFFWS system works with this.

Build a Compound Pulley

Since system does not allow for setup of complex block and tackle style pulleys, setup the environment for the player to build their own. This gets around the inability of the system itself by letting the player set it up. This would require building the environment in such a way (such as veritcal moving platforms or stairs around) to let the player move the rope through a series of wheels to build this pulley.

Lift Heavy Object

One end attached of the rope is fixed to a very heavy or massive object. The other end is where work is done to try to lift the heavy object. Examples of this could be a large door or simply a heavy platform. The system focuses on maximizing the overall force output. This will mostly be done by focusing on the free end of the rope, but applying an aiding upward force to the heavy mass may also be factored in.

Thesis Puzzle Generation – Seesaw Information and Variations

October 16, 2019

Thesis Puzzle Generation

Seesaw Variants

Lever Wikipedia Page

Info #1 – Link

By: Wikipedia


Seesaw

General

It’s basically a lever, which has the following definition from wikipedia:
Lever: “a simple machine consisting of a beam or rigid rod pivoted at a fixed hinge, or fulcrum A lever is a rigid body capable of rotating on a point on itself”

There are 3 classes of levers:
Class 1:

  • Fulcrum in the middle
  • Effort is applied on one side of the fulcrum and the resistance (or load) on the other side
  • Examples: seesaw, crowbar or a pair of scissors
  • Mechanical Advantage may be greater than, less than, or equal to 1

Class 2:

  • Resistance (or load) in the middle
  • Effort is applied on one side of the resistance and the fulcrum is located on the other side
  • Examples: a wheelbarrow, a nutcracker, a bottle opener or the brake pedal of a car
  • Load arm is smaller than the effort arm
  • Mechanical Advantage > 1
  • Called: force multiplier lever

Class 3:

  • Effort in the middle
  • Resistance (or load) is on one side of the effort and the fulcrum is located on the other side
  • Examples: a pair of tweezers, a hammer, or the jaw
  • Effort arm is smaller than the load arm.
  • Mechanical Advantage < 1
  • Called: speed multiplier lever

I will first be focusing on alterations of lever class 1 (which seesaw generally falls under) but it is good to keep the other classes in mind as options for later development. The variation of levers (and in turn, seesaws) can be broken down into varying a few factors, which then lead to a few direct varied physics outcomes. I separate them below:

Varied positions of: effort, fulcrum, resistance/load
Lead to varied: force, velocity, final positions

Varieties

The following are just a few takes on overall variations of seesaw and lever setups to provide varied experiences with the same general simple machine.

  • Maximize force to move heavy object
  • Move object at varying velocities
  • Jam seesaw
Maximize force to move heavy object

This follows the same general lever setup each time, with the fulcrum near one end, the effort is applied at this end closest to the fulcrum, and the load is found away at the other end of the lever. The load and fulcrum have little flexibility in this setup, but the effort can be applied in a couple different ways. This can be moving a heavy mass over to it, or dropping a mass onto it from a height.

Move object at varying velocities

There is a velocity of the lever points dependent on the difference in mass at the ends of the lever, which can be used to create a few different effects. A very high velocity can lead to creating a projectile of sorts. Understanding the difference in weights and how they pertain to the overall velocity of the system could be used for timing challenges. Finally, understanding that getting similar forces on each end of the seesaw will provide a slow and steady motion could be used for challenges where the most time possible is needed from the movement of the lever (maybe the seesaw carrying something all the way up resets the seesaw by destroying the object).

Jam seesaw

This approach is just using the seesaw to lift one end, then placing an object in the gap so that further alterations to the seesaw do not allow it to return back down fully to its resting position. This will most likely be used to create ramps of some kind.

Unity Card Game Tutorials – Drag and Drop

October 15, 2019

Unity Card Game Tutorials

Drag and Drop

Youtube – Unity Tutorial – Drag & Drop Tutorial #1 [RPGs, Card Games, uGUI]

Tutorial #1 – Link

By: quill18creates


I was interested at looking into how card games are created in Unity as I was interested in possibly making that type of game and also thought it would be something good to look into for my current research on learning how to effectively create my own class systems that utilize interfaces and inheritance well. Cards are a very obvious type of object that will use a similar setup every single time, so they are a nice simple base to focus on creating a nice class that contains everything you should need for all of your cards. Interfaces could then be a good way to give these elements their interactive components (such as dragging them around or sending them to their proper locations during gameplay).

This video is actually the first in a series of three. They mostly cover interactivity in a card game, with a focus on dragging and dropping, with some visual clarity effects (like moving the cards around for you). There is still some coverage on the general “card” class as well.

HFFWS Fixing and Debugging the Pulley Generator

October 14, 2019

Pulley System Generator

Fixing

Notes:

– Deselecting “Fix Start” and “Fix End” on the Rope component allows for the creation of a simple rope that appears to operate normally, but it is not connected to anything
– “Fix Start” and “Fix End” appear necessary to connect the rope to physics objects

TESTING

Issue 1:

Instantiated Rope is a completely broken mess of physics masses jumping around.

Test 1:

Changing objects at ends to TestBox and TestSphere just to simplify the physics objects involved to see if that makes diagnosing the problems easier

Results:

This did result in a more stable rope. It was still not in the correct location, but the rope was no longer just a jumbled bumbling mess of masses.

Issue 2:

Rope is instantiated in a strange position away from most other objects.

– This appears to be because of the ropeStart and ropeEnd positions. The rope is still following their positions, and they are far away.
– The ropeStart and ropeEnd positions however do have the same Y and Z values, suggesting that they are following the logic to some degree, but not as intended.

Test 1:

Change instantiation process so that pulley end objects are instantiated as children of the overall pulley prefab.

– The idea is that this will help with relative positioning
– I am not sure if I can use this method with a prefab that has not been instantiated yet (seems strange using the transform of an object that does not exist yet)

Results:

– This did properly situate the rope end physics objects at the ends of the rope, however the rope was still spawning in a location that was unintended, below everything else.
– The rope also does not appear to actually be bound by the end objects either.

Test 2:

Debug.Log all the positions to see if the positions occurring at run time are matching those in the script.

Results:

– The script dictates that the start physics object is positioned at (-9.5, 0, 0) – (1.0, 0, 0), so (-10.5, 0, 0) relative to its starting position, and the end physics object is the reversse (+9.5 and +1.0). This indicates that there should be 21 units between them. This did happen, but the values are very different looking.
– The start instantiated at position: (-2.5. -14, 35.5)
– The end instantiated at position: (18.5, -14, 35.5)
– This indicates that the parent position they are referencing is: (8.0, -14, 35.5)
– Both RopeStart and RopeEnd child objects’ positions matchup with the weird physics object positions as well, so it’s before them.

SOLVED:

Turns out the overall prefab had the exact transform position (8.0, -14, 35.5) so those values were getting passed into everything as the starting parent transform value

Issue 3:

Rope is not actually connected to the physics objects at the ends.

– This is accomplished by setting the connectedBody reference of the RopeStart and RopeEnd objects to the rigid body components of the start physics object and end phsyics object respectively.
– This is happening as seen in the references at run time, which makes me expect that this connection is still somehow ‘ being made before the instantiation of the full pulley setup.

Test 1:

Run everything in Awake instead of Start

– I thought running everything sooner may help set the connection up earlier.

Results:

– There were no noticeable differences.

NEXT STEPS

Figure out how to actually connect the objects to the ends of the rope.

Classes of AI Agents

October 10, 2019

General AI

Classes of AI Agents

Agents in Artificial Intelligence

Info #1 – Link

By: Sahil_Bansall


Classes of Agents

This link goes over some of the basic setups for a few different classes of AI, which are as follows:

  • Simple Reflex Agents
  • Model-Based Reflex Agents
  • Goal-Based Agents
  • Utility-Based Agents
  • Learning Agent
Simple Reflex Agents

These agents simply react to the current percept, with no regard to percept history. It uses condition-action rules, which simply map a state/condition to an action. So these take in some input with sensors of some type, and then depending on solely that input, it decides an action to take at that time.

Model-based Reflex Agents

These find a rule whose condition matches the current situation. This agent adds an internal state, which is updated with each percept depending on the percept history. This internal state allows the agent to create its own model of the world that cannot be perceived. This agent updates its state with information on how the world evolves independently from the agent, and how the agent actions affect the world.

This type of agent starts to work well with a partially observable environment, since it can make its own “guess” at the full world by making its own models.

Goal-based Agents

These agents make decisions to reach a goal (desired situations). Every action they take gets them closer to the goal. This generally involves using searching and planning.

Utility-based Agents

These agents base actions of preference (utility). How “happy” an agent is is sometimes used to describe its utility. These use utility functions to map a state to a real number which can evaluate what action will make it most happy.

Learning Agent

This type of agent starts with a basic knowledge but then acts and adapts through learning. This learning is done through the use of 4 key conceptual components:

  • Learning Elements: makes improvements by learning from environment
  • Critic: Gives feedback to learning element to inform agent how well it is doing relative to a fixed performance standard
  • Performance Element: selects action
  • Problem Generator: suggests actions that will lead to new and informative experiences

HFFWS Rope Pulley System Issues and Strange Audio Instantiation

October 9, 2019

HFFWS Thesis Project

Creating Pulley System

Creating Pulley in HFFWS

Working with the Rope Script

The Rope script is the central focus for the pulley system, but the Fixed Joint that goes with the rigid body of the ropeStart and ropeEnd also play a crucial role which makes getting everything to work together nicely a bit of a challenge. I want the setup to be able to take in a prefab for each end of the pulley and instantiate those objects in the proper position, and then become connectedBody for each of these Fixed Joints. Similar to other issues I have had before with instantiating objects, there seems to be a critical timing factor needed on top of the fact that the objects just physically behave very weirdly when created.

I think currently there is some collision issue that is occurring because the rope ends up spawning very far away from where it is intended to spawn and also waves around violently. Meanwhile, the objects that are supposed to be at the rope ends are spawning in the correct position. The demolition ball just falls to the ground while the hinged platform moves back and forth some.

The connectedBody reference on the Fixed Joints is something that needs to be done on initialization to work properly, so I have been trying to instantiate the rope end objects first, then setting the prefab’s Fixed Joint connectedBody’s to these objects’ rigidbody’s, and then instantiating that prefab, but this is clearly leading to some significant errors. I will have to try some other approaches where I change the order of events to see if I can get more desireable results, or just understand where the errors are occurring more accurately.

Weird Audio Issue

Weird Siege(Clone) Issue There was a Siege(Clone) object being instantiated at game start. This had lots of audio files. I tracked this to the Level gameObject which has a SoundManager component. This had a Stored State of Siege which I removed. This stopped Siege from instantiating anymore. I am not sure how this got set in the first place (may happen when loading other scenes or checking the prefab scenes). The SoundLibrary component also has a Siege reference in its path: Path = 6Siege. However this does not appear to be doing anything currently.

UnityLearn – Beginner Programming – Pt. 02

October 8, 2019

Beginner Programming: Unity Game Dev Courses

Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Understanding Types

What is a Type

Overview: Types of types, “var” keyword, enumerations, generics
Data Type: data type or simply type is an attribute of data which tells the compiler or interpreter how programmer intends to use the data.

Types of types: Value types and Reference types
  • Value Types: Memory is allocated directly and inline on the stack
  • Examples: int, byte
  • Reference Types: Memory is allocated randomly on the managed heap
  • Examples: Classes, delegates, interfaces
Memory Allocation by Type
  • There are two main memory storage locations we are concerned with, the stack and the heap.
  • Value types and pointers to reference types are located in stack (pointers not directly used in C#)
  • Reference types are located in heap
Stack vs. Heap
  • Stack
    • Allocated when compiled
    • Data are stored sequentially
    • Variable size must be known
    • Not subject to garbage collection
    • Very fast
  • Heap
    • Allocated during runtime
    • Data are stored randomly
    • Variable size can be unknown
    • Subject to garbage collection
    • Slower

The var Keyword and Anonymous Type

The var keyword allows for implicit typing but must be used within method scope. C# can use the value of a var variable it is initialized to to determine what the type should be. This is implicit typing. This also means we cannot declare a var variable without intializing it. Type inference occurs at the compiler level, so it does not effect performance.

Anonymous Type
  • An unnamed container for properties
  • properties are read only
  • no type name available to source code
  • type of each property is inferred

Enumerations

Enumeration: value type that represents a set of related named integral constants; declared using enum keyword
The underlying type of each element of an enum is int. These default to having values of 0, 1, 2, etc. The underlying int values can be set for each element individually however if wanted.
Benefits of Enumerations:

  • value types
  • express and limit available options for a variable’s value
  • named values provide readability
  • leverage Intellisense

Generic Types

Generics allow you to defer type declaration until use.
Benefits of Generics:

  • flexibility
  • code reuse
  • performance
  • type safety

Generics are used with the syntax of , where T is a type parameter. An example is shown below:
private void Evaluate(T suppliedValue)
{
Debug.LogFormat(“the Type of {0} is {1}”, suppliedValue, typeof(T));
}

Generics can be used in similar scenarios where overloaded methods would make sense, but would clutter things because there are many different types you would like a similar method to be able to use. Since you are also using a single method for vaarious types, it will also be performing the same actions on those types, so overloaded methods may be better if you want different actions for different types.

Working with Groups of Types

Module Introduction and Setup

Overview: arrays, generic lists, dictionaries, Queues & Stacks

Arrays

There was nothing new here.

Generic Lists

Lists are part of the System.Collections.Generic namespace. Lists are a generic class that use the type T type parameter.

Dictionaries

Dictionary: in C#, it is a collection type defined in System.Collections.Generic namespace that can store any data types in the form of keys and values.
Similar to other type parameters, they are declared between angle brackets for dictionaries. In arrays and lists, the elements are referenced by an integer index. A dictionary allows you to use a different type of index to reference your collection elements.

Queues and Stacks

Queues and stacks are used for more transient data, as opposed to arrays, lists, and dictionaries which are for more persistent data. The main difference between queues and stacks is the order in which data is removed. Queue is FIFO (First in, First out), where stack is LIFO (Last in, First out).

Coroutines

Introducing Coroutines

Coroutine: In Unity, a function declared with a return type of IEnumerator that allows execution to be suspended and resumed using the yield keyword.
Coroutines allow execution to be suspended and resumed using the “yield” keyword. The execution will run until it hits this keyword, then suspend this operation based on the value returned. This lets Unity continue any other operations going on while retaining its place in the coroutine. The value returned determines how long execution will be suspended. For example, returning null simply suspends execution until the beginning of the next frame. This ability to suspend and resume coroutines is what makes them so useful. The fact that coroutines must be of the return type IEnumerator dictates what values it can return, which means it dictates what values can be used to determine the time its routine execution can be suspended.

Delaying Execution

Coroutine Wait Types:

  • WaitForSeconds(): waits using scaled time
  • WaitUntil(): suspends execution until supplied delgate evaluates to true
  • WaitWhile(): suspends execution until supplied delgate evaluates to false
  • WaitForEndOfFrame(): waits until the end of the current frame
  • WaitForFixedUpdate(): waits until the next fixed frame update
  • WaitForSecondsRealtime(): waits for some time, but uses unscaled time
Time.timeScale

This can be used for a slow motion effect, or even pausing the game in Unity. Setting this to 0 is a common technique for pausing a game. Since WaitForSeconds uses scaled time, this will also stop any coroutines using that as the return type. However, if the coroutine uses WaitForSecondsRealtime(), which uses unscaled time, it will continue to run even at a Time.timeScale of 0. This difference can be useful if you want certain UI elements to perform some action for example while your main game is paused.

IMPORTANT: Yield statement does not return out of the function, it simply suspends execution. When it resumes, it picks up right where it left off.

Running in Parallel

Coroutines can be used for parallel processing. Coroutines allow processes to be split across multiple frames. This can also be used to let them be run in parallel with other game logic to minimize impact on frame rate.

Module Summary

Stopping a Coroutine:

  • StopAllCoroutines(): stops all coroutines running on a MonoBehaviour
  • StopCoroutine(): stops a specific coroutine running on a MonoBehaviour

The way coroutines are stopped depends on how they were started. If started with a string, they must be ended with a string. If started with a reference to the routine, it must be stopped using that reference.

Coroutine Caveats

  • can result in unexpected behavior (it is very easy to accidentally run a coroutine more than once)
  • can make debugging more difficult, since one or more coroutines can be running at a time along with update
  • can be complex and difficult to manage