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!

Dungeon Layout Metrics

So, for the current branch of changes, I’m working on level layout, design metrics, and baseline functionality.  What does all of that mean?

Layout Metrics and Design
Layout Metrics and Design

In the above photo, I have a nearly perfect layout.  The spanning tree options have kept the start (blue dot – bottom right) and end (red dot – center) pretty far apart.  The blue dot is the actual portal where the player would enter the level.  The red dot is just a red colored portal, but that portal is a marker for where the boss room will eventually be.

Of course, since everything is randomly generated, no two levels will be completely alike.  Unfortunately, that means as I change things up or even hit a seed I don’t like, things can go south.

Too Much Spanning Tree
Too Much Spanning Tree

The above shot is with a bit more weight on the spanning tree node.  There’s still a nice long path between start and end, but there are also long hallways that loop too far around (for my taste, at least).  Actually, the above example isn’t awful, but these images are the same seed, the first with 0.05 spanning and the second with 0.15.  While the spanning value may be static on all levels, there may be some small fuzziness around those as well.  Trying to find boundaries is more of a balance than I expected.

Other than basic parameters, I’m trying to prevent barrels from spawning inside of walls:

Barrel Wall
Barrel Wall

Or in large groups that get in the way:

Too Many Barrels
Too Many Barrels

I’ll be working on better “torch flicker” – right now it’s a bit stuttery looking, and I’d like it to be smoother and look more like an actual torch.  Then a few more mobs, the boss spawn, and some more decoration for the level.

Archimatix: A New Tool and Some Thoughts on Labyrintheer

So… how’s things?  Yeah, that’s cool.  I’m over here playing with Archimatix (AX) and it’s pretty much the best thing ever.  I’ve been watching this great tool develop over the past several months (though the dev has been working on it for much, much longer than that), and I have to say that I am incredibly impressed.  I’ve been fooling around with tutorials and random stuff for the past day to see how things can fit into Labyrintheer.

If you recall my earlier posts on the topic, I am not an artist.  I am especially not a 3D modeler.  Much of what I’ve been able to accomplish thus far has been thanks to the incredibly awesome 3D assets provided by InfinityPBR.  I’ve seriously considered how I’d ever get those sweet, custom models for some of the things I’ve considered in Labyrintheer over the past few years, and AX is the answer (I hope).

I’ve been messing with some of the node types just to get a feel for it, and one of the things I wanted to be able to do was some oddly modern, organic shapes as structures and “art” statues in some areas – mostly towns and wilderness, but not so much dungeons and caves.  This was my first attempt at using the FreeCurve node to knock out from a block and have a very open and extremely simple thing.

Ignore the robot – I don’t think that Labyrintheer is going to have robots.  But Robot Kyle is the AX spokesbot and it here just for scale.

While this won’t make it into the game, I don’t think, I plan to use this concept to create monoliths that showcase the twelve elements in the game.  This was actually an attempt at using something like a freehand drawn Fibonacci spiral as a cutout.  It didn’t do quite what I expected it to, but that’s part of the true fun with AX…  the things that don’t work the way you expect, but give you interesting new ideas.

At any rate, I’m sure I’ll be posting about AX now and then and maybe even showing off some assets that could end up in the game.  But for now I cannot recommend Archimatix highly enough for any Unity developer or artist.  It’s an utterly fantastic tool.

Shout Out – Kingsway OSRPG

I’m a sucker for unique ideas and people bucking the status quo.  Today, I read about Kingsway for the first time.  The idea of an OSRPG (Operating System Role-Playing Game) is definitely unusual.  I’ve played an RPG built entirely in Excel.  That was pretty unique.  But a game that mimics an operating system makes me smirk.  Of course, how enjoyable it will be is yet to be seen, but kudos to Andrew Morrish for a new twist in gaming.  I’ll be keeping an eye on this.

Sidestepping

It’s been a bit since I posted last, but that doesn’t mean nothing has been happening.  There’s been some good progress on controls (which is actually kind of a pain in Unity), some work on mob AI (they attack now, animate properly, and even have sound), and some various fixes and clean ups in the code and the project base.

Additionally, I’ve started a second project that I hope will eventually be used in Labyrintheer, as well as be available for anyone to use on the Unity Asset Store.  More details to follow, but I’m hoping to have a really complete and useful package.  Only time will tell, I guess.

Lastly, the second project won’t consume all of my development time, so there should still be (semi-)regular updates on the blog about what’s going on.

Fun with shaders

After getting the debacle with my git repo fixed up, I decided to work on some shader stuff.  I’ve never made a shader before, so I started with some great tutorials Makin’ Stuff Look Good in Unity, a great series of tutorials for Unity devs.

I started out with the tutorial on Winston’s barrier from Overwatch and this is what I had:

Initial Fire Shield
Initial Fire Shield

It looked pretty cool, but wasn’t much different than the tutorial, and also the hex pattern looks far more sci-fi than fantasy RPG.  I made some modifications using temporary PNG assets that I reworked the RGB channels on and ended up with this:

Arcane Fire Shield
Arcane Fire Shield

Much better – arcane symbols work more nicely than the hexes.  Of course, this will be developed over some time to get a better effect, then slightly modified for different elements (there are 12 of them in the game).

Anyone following this at all might be asking: “why the heck are you working on shaders and effects when the game systems aren’t done yet?”  I think it’s a valid question.  Most blogs and books on game development seem to point to it being better to get functionality in, then make things look good.  There’s probably wisdom in that, and I’m sure it works for a lot of people – maybe most people.  But I thrive in chaos.  I also have a bit of the ADD.  And being a (semi-)solo developer, I have to really work on all of the things, so…  sometimes I jump around to not get bored or when I get stuck on something and want to revisit it later.  There’s nothing wrong with this.  Always find the work flow that works for you, rather than trying to fit yourself into the work flow you read or learned about.

Sometimes things just go wrong…

So, I lost 1-2 weeks of development time because I hosed up my git repository.  Anyone else ever do that?  Anyone?  *crickets*

Well, since the whole point of source control is to protect you from these things, clearly I did some very bad things.  Turns out it was a series of bad things.  First, I change my asset serialization to force text.  That part was fine, except then I had a failed merge and merge conflict markers got dumped into the files – which can’t happen with binary files.  At the same time, I was setting up LFS for binary files.  I’m not sure what I did wrong there, but LFS half-worked.  At some point files duplicated, went to LFS but then the pointers in the repo were overwritten by the original binary files.

At this point, I was hosed up good.  My repo was well over it’s limit, I couldn’t push anything (not that I wanted to), and was having a hard time finding a commit I could roll back to that was good.

Now, I have a working copy of my project.  But it doesn’t work for everybody, so something is still amiss.

 

At least it loads now, right?

Update: Navigation

So I finally got the NavMesh functional with waypoints and mob movement.

screen-shot-2016-12-10-at-11-10-07-pm

I do need to pare down the waypoints in long corridors, especially since I’d like to increase the number of corridors and lower the number of rooms for a given labyrinth size.  But…  progress!

screen-shot-2016-12-10-at-11-10-58-pm

I also need to work on spawning – there sure are a lot of Icy Cubes down in the lower left corridor.  I do believe the spawning mechanics are off a bit.

Icy Gel

Hopefully this week, all spawning and path-related AI will be resolved.