How to Draw with Colored Pencils

October 28, 2019

Colored Pencils

Better Fundamentals

DO’S & DON’TS: How to Draw with Colored Pencils

Tutorial #1 – Link

By: Kirsty Partridge Art


I am trying to get back into some activities I liked doing in the past but have not found time to do them recently. Using colored pencils was always something I enjoyed, so I would like to get back to using them to just do some simple coloring and sketching. This seemed like a good time to improve on how I did this as well, so this video seemed like a good start to learn some basics to work on if you want to actually get better at using colored pencils.

UnityLearn – Beginner Programming – Delegates, Events, and Actions – Pt. 04

October 25, 2019

Beginner Programming: Unity Game Dev Courses

Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Delegates, Events, and Actions

Delegates

Delegate: in C#, a type designed to hold a reference to a method in a delegate object

  • Delgates are created using the “delegate” keyword.
  • They are defined by their signature, meaning their return type.
  • Finally they have parameters which they take in, similar to methods.

Using a delegate allowed us to parameterize a method. Using the delegate as a parameter for a method also allows us to use any method which matches that delegate’s signature to satisfy the parameter.

These are some snippets from two scripts, GameSceneController and EnemyController, that show some basics of utilizing delegates:

– In GameSceneController script
public delegate void TextOutputHandler(string text);

public void OutputText (string output)
{
Debug.LogFormat(“{0} output by GameSceneController”, output);
}

– In EnemyController script
void Update()
{
MoveEnemy(gameSceneController.OutputText);
}

private void MoveEnemy(TextOutputHandler outputHandler)
{
transform.Translate(Vector2.down * Time.deltaTime, Space.World);

float bottom = transform.position.y – halfHeight;

if(bottom <= -gameSceneController.screenBounds.y)
{
outputHandler(“Enemy at bottom”);
gameSceneController.KillObject(this);
}
}

For example, in our case we created a public void delegate with a string parameter called TextOutputHandler. Then another one of our methods, MoveEnemy, took a TextOutputHandler as a parameter, named outputHandler. Any method matching the signature of the delegate (in this case, public void with input parameter string) can satisfy the input parameter for the MoveEnemy method. As can be seen in the example, whatever method is passed in will be given the string “Enemy at bottom”.

A delegate used this way is commonly known as a “Callback”.

Events

C# Events: enable a class or object to notify other classes or objects when something of interest occurs.
Publisher: class that sends the event
Subscriber: class that receives/handles the event

Things like Unity’s UI elements use events inherently. For example, the Button script uses events to tell scripts when to activate when a button is clicked. This is different from a basic way of doing inputs which checks every frame if a button is being pressed (which is called “polling”). This is also why creating UI elements in Unity automatically creates an EventSystem object for you.

In C#, events are declared using the “event” keyword, and all events have an underlying delegate type.
C# events are multicast delegates.
Multicast delegate: delegate that can reference multiple methods

To help with my understanding, I tried testing the setup without having an EnemyController parameter to see why it was needed. I discovered it was necessary to pass along the reference so the small event system knew which object to destroy when calling the EnemyAtBottom method. Using Destroy(this.gameObject) or Destroy(gameObject) both just destroyed the SceneController as opposed to the individual enemies. This also helped me understand that adding a method to an event does not pass the method over as an equivalent, it simply means that when that event is called, that any methods assigned to it are also called in their current location in a class. So even though the event was being called in the EnemyController script, the method I added to it was still called within the GameSceneController script, which makes sense.

Example:

In EnemyController script


public delegate void EnemyEscapedHandler(EnemyController enemy);

public class EnemyController : Shape, IKillable
{
public event EnemyEscapedHandler EnemyEscaped;

void Update()
{
MoveEnemy();
}

private void MoveEnemy()
{
transform.Translate(Vector2.down * Time.deltaTime, Space.World);

float bottom = transform.position.y – halfHeight;

if(bottom <= -gameSceneController.screenBounds.y)
{
if(EnemyEscaped != null)
{
EnemyEscaped(this);
}
// Can be simplified to:
// EnemyEscaped?.Invoke(this);
}
}
}

In GameSceneController script:


public class GameSceneController : MonoBehaviour
{
private IEnumerator SpawnEnemies()
{
WaitForSeconds wait = new WaitForSeconds(2);

while (true)
{
float horizontalPosition = Random.Range(-screenBounds.x, screenBounds.x);
Vector2 spawnPosition = new Vector2(horizontalPosition, screenBounds.y);

EnemyController enemy = Instantiate(enemyPrefab, spawnPosition, Quaternion.identity);

enemy.EnemyEscaped += EnemyAtBottom;

yield return wait;
}
}

private void EnemyAtBottom(EnemyController enemy)
{
Destroy(enemy.gameObject);
Debug.Log(“Enemy escaped”);
}
}

I’ve simplified the scripts down to just the parts dealing with the events to make it easier to follow. As I understand it, we create the delegate: public delegate void EnemyEscapedHandler(EnemyController enemy) in the EnemyController script (but outside of the EnemyController class). Within the EnemyController class, we create an event of the type EnemyEscapedHandler, so this event can take on methods with the same signature as EnemyEscapedHandler. Within the MoveEnemy method, we invoke the EnemyEscaped event and satisfy its parameters by passing in this, which is the unique instance of the EnemyController script (after checking that there is a method assigned to this event).

Then in the GameSceneController script, we see that when we instantiate an enemy, we keep a reference to its EnemyController script. This is to assign the EnemyAtBottom method to each one’s EnemyEscaped event. Now anytime EnemyEscaped is called in the EnemyController script, it will then call the EnemyAtBottom script here, passing whatever parameter it (EnemyEscaped) has to the parameter for EnemyAtBottom. In this case, passing this in EnemyEscaped ensures that EnemyAtBottom knows which enemy to destroy.

Actions

Actions (C#): types in the System namespace that allow you to encapsulate methods without explicitly defining a delegate
In fact, they are delegates
Actions can be generic

An Action is just an event delegate that does not need another delegate to be created first to be used as a reference. The Action itself determines what parameters are necessary for the passed methods.

Thesis Project – Concepts for System to Control Script Timings

October 24, 2019

Working with the HFFWS

System for Properly Timing Running of Scripts

Discovering the Timing Issues with the HFFWS Tools

While working with the Rope script in the Human API, I was again encountering timing issues when trying to accomplish tasks through script. I was having trouble instantiating and connecting rigid bodies to the ends of the rope in script. I ran several tests to confirm the timing issues I was having again.

Test #1
  • 2 Rigid Body objects exist in scene
  • Script has 2 gameObject references for those objects
  • Script sets startBody and endBody references to those objects at Start

This did not work. The references could be seen as being properly assigned in the Rope script in the editor, but that connection was being made too late and having no affect on the objects.

Test #2
  • 2 Rigid Body objects exist in scene
  • Script has 2 gameObject references for those objects
  • Script sets startBody and endBody references to those objects at Awake

This did have the intended result of connecting the rigid body objects to the rope.

Test #3
  • All done in Awake
  • 2 Rigid Body objects instantiated into scene
  • Script sets startBody and endBody references to those objects at Awake

This did work once, although I had some issues repeating it afterward. The objects were prefabs which were instantiated in Awake. GameObject references were created for these, and used for the values of the Rope script startBody and endBody, all done in Awake as well.

Test #4
  • Start or Awake is irrelevant here
  • Object with Rope script starts deactivated
  • 2 Rigid Body objects instantiated into scene
  • Script sets startBody and endBody references to those objects
  • Rope object is then activated

This is the best solution that works, as it can be done in Awake or Start. This leads to a much more controllable environment which is ideal for our system. This will be the foundation for the main systematic approach.

System for Controlling Awake Calls for HFFWS Objects

Deactivating/Activating Objects or Enabling/Disabling Scripts

The combinations of all of these tests, most notably Test #4, showed that some important connections are made during the Awake phase of many HFFWS objects. It is important to note that Test #4 specifically indicates that a lot of the important functionality may be happening in the Awake method of the scripts of the individual objects themselves (which is important to differentiate from some system wide class that is making connections in Awake). This important differntiation leads to this option of simply deactivating objects with HFFWS scripts (or possibly disabling the scripts specifically) to force their Awake methods not to run before my systems are ready for them. I can run my scripts, and then activate the HFFWS objects so their Awake methods run at that point instead.

This concept seems the most promising for safely and consistently controlling the timing of my script elements versus those of the HFFWS objects (since I do not have access to their core scripts). As this is a common issue I have run into with many objects, it makes sense to make a small script to attach to any prefabs I will be instantiating which can just hold references to gameObjects and/or scripts that I will need to have deactivated or disabled initially, and then activate or enable after everything is properly set.

Script Execution Order

This was actually the first idea to get around these timing issues, but it seems less safe so it will most likely only be used as a last resort. The HFFWS package already has a lot of various scripts ordered in the script execution order of Unity, so there is already a precedent set by them for when a lot of things should run relative to each other.

To test that this worked in the first place, I ran a test with everything being set in Awake not working but moving it to the first script in the script execution order actually made it work. This was a similar test with connecting rigid bodies to a Rope script object.

This is not an ideal process to use however as it can easily lead to weird behavior that is very hard to debug and will not scale well in general. Because of these factors, I will mostly be looking to expand upon the other system concept.

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.