And we’re back (for real)

So, I know I said “my bad” last time, and that was six months ago.  But, Labyrintheer development has actually kicked back off and progress is being made.  Prior to giving it a break, I had two nagging issues that I couldn’t overcome.

#1 – the small one.  All chests that could be looted (advanced props) have a model and animation path that starts with them open (sort of in their T-pose).  The first thing that happens on instantiation was that they close, and in doing so, play the appropriate sounds.  It was a loud and obnoxious thing – small, but annoying.  Anyway, that’s been dealt with.

#2 – the big one.  Both the player and mobs have evolved over my time with Labyrintheer. They started with CharacterControllers because, well… they’re easier in a lot of ways.  But, despite literally weeks of effort, I couldn’t prevent the player from climbing atop the gelatinous cubes when they pushed against one another.  It was frustrating.  And it appears, in part, to have been caused by having both a CC and a Rigidbody.

I started using the Rigidbody because with only CCs, the mobs would push the player around too easily.  The fix, at least so far as planned, is to remove the CharacterController components, wire all the player controls to appropriate Rigidbody physics, and probably just not use CCs anymore.  It’s not a huge amount of work, just need to get physics movement working (and feeling) right.

All of this is coupled with trying out Unity’s Collaborate rather than my existing git repo.  I’ll probably maintain git, at least for a while, but Collaborate really does seem pretty nice, and I don’t have to worry about git vs git-LFS.  Let’s see how that ride goes.

Otherwise, I plan to maybe use another platform for bug/issue/work item tracking.  Anyone have any tips?  I’ve been toying with #Slack, and trying to find a plugin, perhaps, that would work for such a thing. Conclude would be okay if I didn’t mind eight million channels (one for each issue).  Maybe there’s a better way.

Anyway, for what it’s worth, I should be posting here much more often.  Thanks for hanging around!

Work in Progress – 2017/10/17

A lot of core work on the project has been done over the past couple of weeks – and by core I mean behind the scenes.  Yeah, I say that a lot and rarely have something new to show, and this is one of those times.

However, as an independent developer, that’s how a lot of this process goes. I fixed the helium filled GelCube issue, and they seem to be functioning fairly well on their NavMesh.  Part of this was competing systems causing race conditions.  I toyed with the idea of using physics to drive them, disabling some of the Unity AI stuff, but that led me into a rabbit hole that I wasn’t in the mood to contend with.  Instead, I resolved the conflicts and they are now pathing along as they should.

I also added a physics material for them.  They’re made out of ice, and should slide around a bit more than other GelCubes and mobs in the game.  I’m also testing a fun bit where they may have items from their biome shoved inside them…  I mean, they’re likely to pick things up as they move about and grow, right?  I’m hoping this is a small detail that is cool in the long run.  We shall see.

I’ve started setting realistic masses for Rigidbodies as well.  The player has a mass of 81kg, and a full sized GelCube has a mass of 5444kg (who knew they were so heavy, but it does make sense).

Otherwise it’s been more boring: some maintenance to remove old assets that are no longer in play, some scripting for torches, creating static materials from SBSARs now that I have the walls and floors in a good place.  Oh, and modifying the Dungeon Architect DungeonRuntimeNavigation.cs file to support multiple meshes for multiple agents.  If you use DA and are interested, you can grab that here.

DungeonRuntimeNavigation Inspector
DungeonRuntimeNavigation Inspector

Basically you use an int[] to specify the NavAgentIDs that all your mobs will use and it builds all of their meshes and navigation data at the same time.  I know I’m not the only one who wondered for a while why I couldn’t use other NavMeshAgents in my Unity project.

Unity Profiling for Fun (and Profit?)

For those who may have been following since before this blog began, you may have seen the Iceglow Gel death sequence that includes the possibility of spawning smaller Mini Iceglow Gels.  This was, by and large, a stroke of sheer genius on my part (yeah yeah yeah, just let me have this one).  It seemed like a cool idea and has led to some other cool ideas for deaths with other mobs.  In fact, each mob has a DeathScript requirement, even if it’s just to, you know… die.

But this has also been a thorn in my side.  When an Iceglow dies, there is a major stutter before the new minis are spawned in.  I finally decided to toss up the profile to see what was going on, and decided to write this brief post on profiling, because damn, it’s handy!

For those new to Unity or development, the profiler is a pretty common tool used to “debug” the actual running game.  It can attach to a development build for better and more accurate profiling, but if you’re simply looking for bottlenecks where the definitive time and resources aren’t as important as discovering the spike, you can also simply attach the profiler to the editor itself.

Ice Glow Death Profile 1
Ice Glow Death Profile 1

This was a capture at the time of the resource spike right when the Iceglow dies.

Ice Glow Death Profile 2
Ice Glow Death Profile 2

The details of CPU usage show that the >1s spike is caused by the PhysX core baking the mesh for the minis.  I was hoping that, since this was running in a coroutine, that it wouldn’t impact the whole of the game.  Maybe I’m doing it wrong (or, at least, not the best way).  Maybe I can pre-bake those meshes.  Maybe I can use simple colliders instead (a cube is far easier to calculate).  I’m just delving into this, and I’m not sure what the best solution is yet (stay tuned for updates on that, or follow my plea for help), but for now, the profiler is my handy tool to figure out what calls are b0rking the game.

Easily as important as debugging code, and definitely more important for tuning, I can’t recommend highly enough learning to love your profiler.

If at first you don’t succeed, Google some more…

As a lesson, today I taught myself that sometimes your first (several) attempts to Google a problem just don’t do the trick.  For several weeks I’ve had an issue where my mobs just zoomed around like they’d been snorting magic dust, completely ignoring the values set for them with regard to speed, acceleration, et cetera.  It happened fairly suddenly, I wasn’t sure why, and many attempt to fix it failed.

I Googled this issue many times over the weeks looking for an answer.  Nothing relevant ever seemed to make it into my search results.  It became frustrating!

Then, on a whim, I searched once more for the answer, clearly using a better phrase, and Google’s magical algorithm finally decided to lend a hand.  Of course, the answer was something dumb on my part.  At some point, the isKinematic boolean flag on the rigidbody component became unchecked, which meant that the rigidbody and the nav mesh agent were in a race condition, both trying to control the movement of the mob.

But, NO MORE!  My gel cubes gracefully slog around the dungeon biome again, and the War on Magic has been brought to a halt.

One checkbox took weeks to resolve.  Probably a n00b issue, but a good lesson all the same.

Making Materials and Models! Mmmmmmmm (M)Normal Maps?

Not being an artist can seem like one of the most daunting parts of going it alone (or mostly alone) as an indie dev.  I’m a fair photographer, but that’s as far as my artistic capabilities have previously taken me.  Most of my stick figures look, well… disfigured, and things like straight lines are as simple for me as writing in Martian.  But I’ve been really working to increase my skill set here, and be able to create things in Labyrintheer that actually LOOK pretty decent.

In light of that, I started by picking up some great models from InfinityPBR.  Andrew, the awesome dude behind iPBR (as I reference it for myself) includes some great PBR materials as SBSAR files (and recently SBS files) that really helped me delve into how materials work and what was meant by all of the components: normal, roughness, metallic, height (or specular and glossiness depending on your preferred workflow); metallic/roughness versus specular/glossiness; and a bit about what all of those components can do.

But this wasn’t enough customization for me.  As I’ve mentioned before I started using Archimatix to design some architectural models (which is still something I’m getting a handle on, simply due to the sheer variability of AX and its nodes).  As I worked through some (very simple) wall models and such, I realized that I also wanted more control over the materials themselves.  iPBR offers an INCREDIBLE amount of customization, but I’m just a pain in my own arse that way.  So the next step was…  Substance Designer.

For those new to the art game, Substance Designer is an amazing software package that lets you node-author your own materials and export SBSAR files that can be used to procedurally create materials in Unity (and I believe Unreal Engine).

The beauty of the node-driven design is that, while artist-type folk seem to settle into it easily enough, we logic-driven code monkey types can also create some really stunning work since everything can be reduced to parameters and inputs and outputs.  But before you can do any of this, you need to grasp some of the basics.  I’m not high-speed enough yet to really offer a tutorial, but I can share the wealth of tutorial love that I’ve been using.  So, let’s start with normal maps.

Normal Maps

I ran across this tutorial literally this morning, which is what brought me to create this post and share this info.  More blog post, less actual tutorial, the information about normal maps here is presented concisely, tersely, and with excellent clarity.  Even someone who has never heard of a material in game parlance before can probably understand what’s being explained.

The gist of normal maps is to provide interaction between the materials and light in your scenes.  This is not the same as metallic/roughness aspects, but more to “pretend” that there’s dirt, smudges, small deformities or other similar features on your object.  When making a material, you often preview it on a perfectly flat surface.  But you still want to see the details – details that offer a 3D appearance on a completely flat 2D plane.  This is where normal maps come in.

Let’s look at the image below, for instance:

Demon Head Emboss - Coin Face
Demon Head Emboss – Coin Face

This is meant to be the head of a coin I’m working on as sort of a self-tutorial.  The eye can easily see this as an embossed image, but due to the normal map, moving the light around changes how and where shadows happen.  Here the light is off to the left, so left of the “ridges” (it’s still just a flat plane) looks brighter, and right of them produces shadows.  If I were to move the light source to the other side, the opposite would be true.  This is how normal maps help reinforce the 3D appearance of an object that doesn’t have detailed modeling done.  This is a HUGE benefit to game performance – it’s much easier to draw a coin that is perfectly flat on both sides, and apply this material to make it appear 3D than it is to produce a 3D model with this level of detail.  Easier both in actual creation of the object as well as on your GPU for rendering it.

This video shows the coin in Unity.  The scuffs and scratches are both part of the base color of the item, but the deeper scratches are also mostly in the normal map, and allow light to fall into them or be occluded from them based on the light angle.  Note that in the above video, the edge of the coin are NOT flat, those are actually angled on the model itself.  That would not be a great use of attempting to use normal maps to provide a 3D effect (at least not in any way I would be able to do it).

That’s what I have for normal maps, for now.  But I plan to continue this as a growing series of posts on PBR materials to help demystify them for those of us new to this whole thing.

Substances, Dungeon Floors, New Workflow

I’ve picked up Substance Designer and have started working on some better assets for the Dungeon biome.  Right now what I have is a bit busy, but I thought I’d share some of what I’m doing.  I started with a great tutorial on Youtube, where the presenter was kind enough to offer up his SBS file.  I made a variety of modification and exposed some parameters, kicked out the SBSAR and loaded it into my staging project in Unity.

I created three separate materials and applied them to their own GameObjects that Dungeon Architect uses to generate the floor.  Right off the bat, it looked like this:

Attempt 1
Attempt 1

Like I said… busy.  But at least it’s more interesting than what I had before.  I decided to up the game by adding a random rotation – each floor is randomly rotated by 0, 90, 180, or 270 degrees.  That looked like this:

Attempt 2
Attempt 2

Still busy, but at least a little more random.  Then I felt that the stones shouldn’t always be the same size, so I set each to have slightly different numbers of tiled stones per object:

Attempt 3
Attempt 3

Lastly, it still seemed too busy, so I lowered the overall count of each.  One was 4×4, one 5×5, the last was 4×5 making some stones also not square.  That looks like this:

Attempt 4
Attempt 4

Now it’s less busy, more random feeling, and looks decent.  I think I’ll probably go back to the Substance a bit and see what I can do about breaking them up a bit more, but for my first modification of a substance I’m pretty pleased.

Random Class, Singletons, and the “Big Debate”™ (does this sound familiar?)

A few weeks ago I wrote a VERY similar post about my Logger class and the debate over the use of Singletons.

I’ve done the same with my new randomization class, LRandom().  LRandom does several things under the hood, and is a singleton for a very specific reason.  First, I wanted to use it to replace the random class that Dungeon Architect uses during initialization of a dungeon or map.  In part because I wanted more control over randomization, and in part because I wanted all aspects to produce the same values with the same seed.  Previously, at least in earlier versions, DA would produce the same dungeon layout, but things like decorations and extras would not always be the same.

Additionally, I wanted the same random class to be able to control other randomizations during play: loot, die rolls, et cetera.  The current implementation uses a single System.Random instance, though I may extend this to have several – one for dungeon building, one for loot, one for mob AI, and so forth.

Also, the state of the System.Random is stored in a serialized file on exit.  This should, in theory and after a lot more work, allow one to pick up where they left off with the state of the randomizer where it was before.  The main goal here is to prevent “known randoms” with the given seed.  The first chest you run across won’t always have the same stuff.

The class also contains the original DA methods for NextGaussianFloat() and GetNextUniformFloat() to integrate without changing a lot of the DA code.  And lastly, it contains methods that allow the instance to be reseeded if need be, which is mostly good for debugging, but may have benefits during runtime as well.

So, currently, LRandom() and LLogger() are two singletons that I’m using that have proven very beneficial.  If you missed my last post, or want to hear more about Singletons (the good, the bad, and the ugly, so to speak), check out this great podcast from The Debug Log- Episode 73: Design Patterns: Singleton.

How To See Your Player… Making Walls Transparent

Over the past several months working on the Dungeon theme for Labyrintheer, I’ve changed my camera angle several times.  I keep moving it higher to prevent walls and such from occluding the player, but I’m never happy with such an oblique view.  So, over the past few days I’ve been looking at options to make walls transparent when they are between the player and the camera.

Some solutions simply disable the geometry.  This isn’t acceptable for my game, and I suspect for many.  You could accidentally walk backwards out of the playable area, or an errant AI could take a bad turn during it’s pathing and fall off the world.  Plus, disabling geometry just doesn’t seem like an elegant solution.  My primary goal (and I’m still working on it) is to use a shader for this directly, though that seems like it has some major pitfalls (how do you tell a shader about an object other than the one that it’s drawing?).

So, for now I’m cheating with a very small amount of code and an extra material for objects that I want to hide.

Basically, I’ve duplicated the four wall materials I have, and the duplicate materials use transparency with an alpha value of 100.

My player controller script now calculates it’s distance from the camera every frame (though I think this might be able to be done once in Awake() since the distance should be fairly static), like this:

     void Update ()
     {
         GetInput();
         ProcessInput();
 
         distanceSquared = (transform.position - Camera.main.transform.position).sqrMagnitude;
     }
 
     public float Dist()
     {
         return distanceSquared
     }

Then created a script to go on the walls (or any object that needs to be transparent to prevent occlusion), as such:

TransMaterialSwap.cs

 using UnityEngine;
 
 public class TransMaterialSwap : MonoBehaviour {
 
     public Material _original;
     public Material _transparent;
     private GameObject player;
     private playerController pC;
     private Renderer rend;
 
     void Start()
     {
         player = GameObject.FindWithTag("Player");
         pC = player.GetComponent<playerController>();
         rend = this.GetComponent<Renderer>();
     }
 
     void Update()
     {
         if ((transform.position - Camera.main.transform.position).sqrMagnitude < pC.Dist())
         {
             rend.material = _transparent;
         }
         else
         {
             rend.material = _original;
         }
     }
 }

In the inspector I set both the original material and the transparent material.  If the object is between the camera and the player, it switches the object’s material to the transparent material.  It looks like this:

There are a few issues here.  First, I still need to profile this to see if the solution gives my runtime performance a hit.  I don’t suspect it’ll be TOO bad, but it doesn’t hurt to check, especially with larger maps.  I may look into options to only run the check if the object is visible to the camera rather than always checking on Update(), every frame for every wall.  The other issue is that by making it transparent, light comes through.  I’m not sure how big an issue this will be – it’ll require some play testing.  But it may be an issue in some situations.

Lastly, as I said, I really do want to attempt this in a shader.  I figure it’s a good method to learn shader programming, even if exactly what I want isn’t possible.

Logger Class, Singletons, and the “Big Debate”™

So I’ve spent a bit of time working on getting a logger class setup, which is rudimentarily complete.  This class currently just writes out to a file and also to the debug console in Unity.  It takes in a message, a module, and a severity.  I wanted to easily have access to this class from anywhere, but since it writes to a file, I also needed to ensure that there was ever only one instance trying to access the file at a time.  This, of course, led to the singleton pattern.

Now, even a cursory glance through newbie programming blogs and books can cause one to question why this is even a pattern to begin with – it seems that everyone says to stay away from them, and I kind of understand why you don’t want to overuse them.  The Debug Log has a pretty good episode about them here.

So, singleton was the answer, and it was setup nicely enough and it works, though I still need to make it threadsafe.  But… logging:

LOG!
LOG!

So, now it’s back to work on the game itself.  I have most of the systems in place to get a sample level up and running soon.  Yay!