Tower Defense Tutorial Fixing Scene Manager

Tower Defense Tutorial Fixing Scene Manager

June 19, 2019

Tower Defense Tutorial Project

Fixing Problems with the Scene Manager

To help get back into the groove of working on my tower defense project, I went over some scripts that I thought might help fix problems and listed out how they reference each other. (Lower placed scripts reference the higher ones)

Script Reference List

  • PlayerStats
    • LevelPlayerStats
  • WaveSpawner
    • WaveInformation
    • LevelManager

Then I got working on the problems with the scene manager and the method call timings between the different scenes that were giving me errors. There are a lot of issues when references trying to be called before variables are properly set in different scenes, and this offset is leading to a lot of errors where the checks are checking against default values like 0 and null as opposed to their properly set values. So once again, I made a list of problems as I encountered then and possible fixes I tried, including the ones that finally worked and stuck for now.

SCENE PROBLEMS

Problem

Menu buttons do not work

  • Going back to the level select menu screen is not working on either button, so Menu() method must be incorrect
  • The for loop to deactivate level buttons the player should not have reached yet was given the wrong value to start with when reactivating the scene
    • it was setting a value to the active scene’s index and adding that to the for loop check for the level select button array
    • this value was initializing at 0 the first time through for some reason (another scene timing error), but was then being set to 4 when returning (which I believe is the level scene’s index, so this is another scene timing issue, but being properly set to 3 [the index of the level selection scene] would have been bad as well)
Solutions
  • Solution: Just removed the addition of the current active scene build index all together; I think this was added at some point to process the correct level build indices, but that is no longer needed.



Problem

Retry for a level does not work

  • Clicking retry does unload and reload the current level scenes, but it is done so improperly and the timer does not count do to start the first wave ever
  • Just ever unloading a level scene and trying to load it again has the same problems
    • This indicates something is not being properly reset the second (or more) time the scene is loaded
    • Look to individual Level scene and Base scene (created for all levels), especially in Start type methods
    • EnemiesAlive and WaveIndex are not resetting to 0 when scene is unloaded
      • EnemiesAlive specifically is one of the checks to see if a wave should be spawned (spawns a wave when the value is at 0 to make sure the previous wave was defeated)
Solutions
  • Potential Solution: reset these values to 0 when level scenes are loaded
    • tried this by creating a ResetWaveSpawner method in the WaveSpawner itself, then having something reference this on Start with something that is created on Level load
    • started method in Start method of LevelManager script
      • this actually worked for going back to the menu and then trying the level again, but retry still did not work properly
      • I figured this meant the scenes might be loaded/unloaded differently, so I checked my sceneManagerLite and sure enough, the level selection from the menu needed to load both the Base and Level scene, but retry was JUST unloading/reloading the Leve scene, not the Base scene, which is where the LevelManager is located that is resetting the wave spawner on Start
  • Potential Solution: just have the reset called in the Start method of something in the Level scene itself
    • This did allow the level to start properly when returning to the menu and coming back, or with the simple retry. However, there were still some other problems. Now if you beat a level, every time you returned the game won screen would come up and the game would still play in the background. Leaving the level during play and coming back (by menu or retry) would also change the “Rounds Survived” counter at the end, indicating something with the wave counters was not resetting properly.



Problem

Beating Level Once Beats it Forever

  • After beating level, game won screen comes up immediately when going back to the level
  • Back to our game winning bool checks, appears that the WavesFinished bool is not properly reset when returning to a level. This should be false every time the player starts the level, and get set to true when they win. This is happening correctly, but it is never reset to false.
Solutions
  • Possible Solution: reset the WavesFinished bool in WaveSpawner with proper scene timing
    • Actually just added this to the newly created ResetWaveSpawner method I created to deal with the previous resetting issues and this fixed it



Problem

Wave Spawning Coroutine is Off

  • Resetting a level during the spawning of a wave has the rest of the wave spawn immediately (at the beginning of the newly reset level) as well as spawning the second wave (skips the spawn of the first wave all together)
  • This indicates the coroutine spawning the wave might need manually jumped out of on reset and that the wave index is being messed up by their being enemies remaining

Morph Between 3D Objects with Houdini VDB Morph

June 10, 2019

Houdini VDB Morph

Morph Between 3D Objects

Youtube – Houdini Tutorial – 3D Object Morphing using Open VDB Morph and SOP Solver

By: Jeshuran Paul

One of the finishing touches for my frog generator Houdini project that was suggested was morphing between several of the frog objects it is able to create in a single animation. I was already looking into converting some/all of it into VDB objects at some point to help clean up the joint connections in an interesting and organic way, so this VDB morphing seems like it should fit nicely with that.

Frog Body Generator – Houdini Basics of Polywire and Sweep with Ramp

June 10, 2019

Houdini – Polywire and Sweep Nodes

Using with Ramps

Youtube – Houdini Essential:How to control polywire, and sweep node along a curve by ramp parameter. part2

By: Saman khorram

I think this tutorial may finally give me my solution to replace my personally made ramped scaling in Houdini for my frog generator with a more consistent and simple SOP setup. I’ve just needed a way to sweep and then scale separately in the horizontal and vertical direction using a ramp along the line of the sweep.

This ended up just being more about altering the pscale along the line. This just alters the uniform scale of the circles.

Current Fix

I was able to change the vex a bit to give me a more consistent result as of now. I am still using a Sweep of circles over a line and scaling them my own way with a bit of vex, but I’ve just changed how it works.

Initially, I was using this on the circle that I was sweeping:

vector a = set(0, 0, 0);
@N = normalize(a+@P);

v@xScalingVector = set(@N.x, 0, 0);
v@yScalingVector = set(0, @N.y, 0);

I was doing this so that the circles would be able to keep the scaling vector information with them after they were swept to use for the individual axis scaling. This gave me some inconsistent errors though. The body would not be symmetrical, with a bit of a skew.

The scaling was done by using ramps to assign xScale and yScale attribute values to the points of the circle sweep along the path. The scaling was then done with an attribute wrangle and the following VEX:

@P.z += @xScale * v@xScalingVector.x;
@P.y += @yScale * v@yScalingVector.y;

The P.z taking “x” values was because the z values actually dealt with the width of my frog body. This was taking the ramp values and multiplying that with the originally signed scaling vectors and then readding that to the point position. The scaling vector was supposed to help with direction, so the negative values would go more negative and the positive the opposite. However, some points were keeping scaling vector values of the opposite sign, so they would “scale” in the wrong direction and give the weird skew.

While experimenting with some fixes by just using an arc and mirroring it 1 or 2 times, I actually just tried using the normal vectors directly in my wrangle as opposed to the saved values since I thought the saved values may not be working nicely with the curving of my sweep outline. So for the circles pre-sweep, I just kept the initial part of the VEX wrangle:

vector a = set(0, 0, 0);
@N = normalize(a+@P);

And for the scaling wrangle, I just used the @N vector:

@P.z += @xScale * @N.z;
@P.y += @yScale * @N.y;

So far, this at least fixed the issue for now, and has worked with a few variations so I am hopeful this is a decent fix for my issue for now. Random final note, I did have to reverse the normals after skinning when doing it this way for other nodes to work properly (such as the one protruding the ridges on the frog’s back).

AStar for 2D Pathfinding in Unity

June 8, 2019

Unity 2D Pathfinding

Using AStar

Youtube – 2D PATHFINDING – Enemy AI in Unity

By: Brackeys

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

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

Dev Tutorials Breakdown of Creating Entire 2D Game in Unity

June 6, 2019

Unity

Full 2D Game Process

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

By: Dev Tutorials

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

Houdini Frog Generator – Controllers and Foot Webbings

June 4, 2019

Houdini Frog Generator

Controllers and Foot Webbing

Foot Webbing

The general concept was to take a line of points and move every other one along its normal to create a general zig-zag pattern. Then, you resample it to make it smoother and wavier. I have another set of points that are along the foot that will create the inner boundary of the webbing. You then use the Add SOP to create a closed polygon between these line boundaries.

To make this more consistent, I wanted to create the line using points from the toes. This way, the webbing will follow the toes around properly as I shift them around. This was easy to accomplish by just adding another point at the tip of the toe geo and setting it to have an id attribute of 0. I could then connect all of the same attribute valued points in a line with the Add SOP.

The line between all of the toes would then be made up of a number of points equal to the toes. I needed to add a single point between each pair of toes to move to create the wave in the webbing. This could be done with a resample that adds a point in the middle of each polygon.

Controllers

I wanted to practice setting up overall controllers to start making it easier to work with my frog generator from a few ruling nodes.

I first practiced this by setting up a controller for the foot to control the webbing parameters. This controller was tied to: webbing length, webbing curvature, and webbing origin.

The length is how much overall area the webbing covers between the toes. The curvature is how wavy, or how far the inner webbing points are away from the general curve. Finally, the origin just helps move the inner boundary of the webbing around in case it is too far from the foot or too far in.

I then moved on to creating a body controller, which had a lot more parameters. This also required connecting some ramp parameters, which are a bit weird in Houdini.

These parameters include:

  • Body Length
  • Spine Shaping
  • xScaling Body
  • yScaling Body
  • Dorsal Start
  • Dorsal End
  • Dorsal Projection Angle
  • Dorsal Projection Ramp
  • Back Leg Position
  • Back Leg Angle
  • Arms Position
  • Arms Angle
  • Eyes Position
  • Eyes Angle
  • Tympanum Position
  • Tympanum Angle

The body length is just the general overall length of the body shape. The spine shaping is a ramp that lets you add curvature to the body. The xScaling and yScaling are ramps that independantly alter the general width or height of the body throughout.

The dorsal variables control the larger dorsolateral dermal plica on the back of the frog. These are raised ridges a lot of frogs have. These control how far along the frog’s body these ridges go, the radial angle around the body they are projected, and a ramp to control how much it deforms the general body in the normal direction along the ridges.

Finally, all of the positions and angles control the connection point locations for various body parts of the frog to the general body. These select a specific point along the main spine to project out onto the body surface, and the angle determines the radial projection around the body these points are located. These two features together let you place the body parts anywhere on the body very easily.

Creating Houdini Digital Assets

May 28, 2019

Houdini Digital Assets

Youtube – Introduction to Houdini – Chapter 4- making digital assets

By: Rohan Dalvi

Making Digital Assets in Houdini seems to be a core part of creating a procedural model generator, so this tutorial gets into the very basics of setting one of these up.

The practice used here is that you create a Null object off to the side where you “Edit the Paramter Inteferface” under the settings of the node (the gear icon). You select the type of values you want to vary (floats, ints, ramps, vectors, colors, etc.) and add those to this Null object. Specifiying a range here can be helpful to inform the user of useful values. You then “Copy Parameters” from this Null control node, and “Paste Relative Expression” to the nodes/variables that they make sense. This way, when the Null control node has its values changed, they will directly correlate with changing the designated value within your network of nodes.

C# LINQ Extension Methods

May 23, 2019

C# LINQ Extension Methods

Microsoft – => operator (C# Reference)
Youtube – C# Tutorial 13 LINQ Extension Methods

By: Derek Banas

I was working on a tutorial for GPU Instancing and dynamic batching a while ago to look into some ways to visually instantiate a lot of objects in Unity without overloading the computer and there was a lot happening in the code I was unfamiliar with. The biggest parts that stood out were the ” => ” operator along with some list and array methods.

The => operator was used within a list method called “Select”, so I started looking into both of those. The name of the => operator is the lambda operator. The simplest aspect seems to be that it’s a function with the parameters on the left side and the performing function on the right side. IT also seems to be used a lot with LINQ, which I am unfamiliar with.