Start of 2017 and Level Building with Tiled

So despite January being a pretty shitty month regarding personal life with break ups, etc (yeah game devs are humans too, funnily enough :P), the plus side is that I devoted a lot of time and energy into my project that I have been working on for like a million years. “But wait!”, I hear you cry, “your game was an isometric 3D cool looking thing. What is this pixel art thing I see above?” Well I got to a point with the old project where I realised that quite frankly, it was too much for a project I was working on in my free time. I mean, come on. I am working on this awesome game in my day job ūüėČ Anyway the pixel art is not final, it will be top down 2D but it was me learning how to draw and my favorite artist is also getting involved (and not just with Art, with story, design, and all manner of cool things! I am even trying her how to code… kind of :P), along with others so I have a toe firmly up my backside and have people who are skilled at other things to help out. Hopefully we will have something playable in a couple of weeks to see if it is fun and what we need to change to make it fun.

Anyway, on to the technical stuff. Yes the above is still Unity with a combination of 2D toolkit, but we are doing some cool stuff with loading levels, which will also allow us to “hot reload” levels whilst the game is playing. What this means is I can give a standalone build to a designer and Tiled and he/she will be able to hot reload the level.

So OK, what even is Tiled?

Tiled is a powerful Map Editor that allows you draw maps using tile sets. It has been used in a variety of games which I THINK includes Titan Souls and Hack and Slash. If you want to know how it works, Games From Scratch has a really good tutorial on how you can make cool Tile Maps. Essentially it allows us to make layered tile maps that we can use to make cool levels. Note: What I am about to explain is the specific way that I am using Tiled and Unity. There are many ways to do it, but this is the setup for my specific project. This is also unlikely to be super detailed, it is meant to be an overview of what I am doing, not a tutorial.

Above is my setup for my really really basic test level. As you can see I have 4 layers. The top, the middle and the bottom grid layers. Any tiles in the background and foreground layers are visual layers (the foreground layer been drawn in front of level characters such as the player, and anything in the middle level is deemed as a collision object as it is in the same level as the player and other objects are. The Object layers is actually where we set up THINGS or objects in the level. These also have metadata. If I select a waypoint for example.

You will see it has a name, a type and a load of custom properties that I use to hook up the enemies.

I then export this to JSON and it looks kind of like this:

You can view the whole Tiled JSON format here.

OK, I have a load of data, how do I actually get the game to understand it

Obviously, we first load the file as Json.¬†I used MiniJSON to do this and then deal with it. You could do some clever auto-mapping using Unity’s in-built parser or Newtonsoft, but for this I like to have control of what data I actually need and what I am going to do with it.

First I have a prefab that is a tile. This contains three tk2DSprites that represent the foreground, background and middle.¬†We build a number of these tiles the correct distance apart using the width and height of the map defined in the JSON. We then¬†go into the giant data array, convert it to a 2D array using the width and height. and use the indices to set the sprites.¬†All of the spritesheets/tilesets map one to one in Unity and Tiled. The tileset you see in Tiled is exactly the same as the one I use in Unity and 2D toolkit. The indexes in the sprite sheet in the data ALMOST match up to the 2D toolkit sprite indices (out by 1). Using the data level in each layer we set the correct image on the tile. Simple huh. We also set any of the tiles that are populated in the middle layer to “non-walkable” in our¬†A* Pathfinding system.

The slightly more interesting thing is the Soldier. Tiled’s object system is very powerful and can be used for a load of cool things. Unfortunately in our use case it represents object positions in pixel space rather than the tile systems grid space.¬†I have set rules for the designers that the objects must be one tile size large (which is 32 x 32) in our case and must be snapped to a tile position. You can draw objects anywhere in the object layer of any size, however that is not the way our game is using the tool. Like I said, if you look in the image above in the player object we get the x and y in pixel space. How do we find the grid position? Divide it by the tile width and height respectively. Using this data, it loads prefabs and populates them in the correct places on the map. These objects then use the propertiesd ata that we set up in the metadata in Tiled:

To populate things like what waypoints belong to which enemy, what AI behavior should that enemy use, etc, etc.

Anyway, I know that was quite a bare bones overview, but I hope you found it interesting at least and a bit of help if you are using Tiled with Unity or any game engine!

Share

2016

I could start my 2016 post by going on about Brexit, Trump and how we are all fucked, but we have every other news establishment doing that for us, so I am just going to take apart my experiences and do my standard view of the games industry and all that jazz.

To be honest, my personal 2016 has not been terrible. I managed to buy a flat and got made a lead programmer.

The former obviously came with some caveats of having a lot of help and of course later on a neighbor from hell moving in next door, but hey that is life, I am on the ladder, I love this flat although I am not planning to stay here forever and I know how much I need for the next one!

Being a lead programmer was certainly a good jump, what you have to remember is that the lead programmer title is a ROLE and NOT A PROMOTION. You don’t necessarily have to be the most senior person to be a lead, just have to be the right person for the project. I mentored junior and was leading my old mentor, I learned a lot, and it was really worth it. You end up doing less porgramming, but I really like bringing out the most in my team!

There were some downsides. I have suffered a couple of projects being canned/put on hold. It is always tough, but as I have always said, for good or bad games like any other creative industry is a business, so you just have to crack on even when there are disappointments.

Right that is the personal stuff I care to share, what about games?!

Before I go in talking about what games were really cool, etc, I want to talk about a specific event that happened this year that I fundamentally disagree with. The whole No Man’s Sky Day 1 patching. Certain “indie heroes” or whatever the hell you want to call them went on about how the process is wrong and how to certification is stupid and¬†how the console holders “aren’t built for 2016”. They also moan about the actual parts of the cert process. I actually think “if you rapidly plug in and remove the controller” as actually a completely legit test. Why? Because users are stupid and some idiot will try it. Next question. I could go on and on about this until the cows come home and it would sound really really ranty, in the end I disagree.¬†Here is an example of an article I don’t agree with¬†regarding this fiasco. I am in the complete opposite camp. When the game gets to disc, the game should be almost perfect. The experience they are expecting should be the one they bought on the disc. They shouldn’t have to rely on day 1 patches that are huge and rape our monthly download limits (I don’t have one personally, but someone will), this whole “oh they have got an extra month or 2 since going gold so we should continue making the best possible game”.. no, not if it changes a LOT of stuff fundamentally, in fact that sounds like either feature creep or piss poor planning. The cert system is not old an convoluted. It is complex and necessary to keep the quality bar high.

Did I mention that No Man’s Sky had several HARD crashes after the patch? Yeah that would have been a certification fail.

Cool, mini-rant over.

One of the biggest surprises I had of this year was DOOM. Like everyone else I was like “meh, Doom, OK”, but after picking it up on a whim, I was suprised. In fact it was probably some of the most fun I could have had with my pants on this year. It was a game that was just… well fun. It knew exactly what it was and I loved it.

We had some Kickstarter game scome out including Mighty No 9 (ewww) and Hyper Light Dirfter (yay!) although my general experience with kickstarter has been absolutely terrible with lots of stuff never arriving even after I had paid for it! (Never use Kickstarter!)

We had a few remastered editions come out. I have really enjoyed revisiting Rapture in Bioshock and fighting for Europa in Valkyira Chronicles.

I also loved playing through the spiritual successor to Chrono Trigger, I am Setsuna, and trying to keep all my characters alive in Fire Emblem Fates. Also Bravely Second is a nice return to that world.

In stealth land, we got the Republiqe remaster, which was great as I had a Unity game on a disc which made me feel better about my career in general (I always wanted to realease a game on a disc and it seems a bit more realistic now). But more importantly we got Hitman.

Episodic Hitman was a stroke of genius. The levels themselves were mini sandboxes you can get lost for hours and were by no means “one-shot”.¬†There are hundreds of different ways to take down the story targets, elusive targets that you only had one go at and finally you had the ability to make your own mission and share it. It is a great package!

Uncharted 4 was also a thing, I really enjoyed it, but I assume everyone has played that game, so you all know how awesome it is!

We then had the summer of Pokemon Go. Although I am not playing it now as in my opinion it is not a proper pokemon game, we had some good times trying to catch them all! It was pretty short lived though…

Deus Ex was worth playing, although it wasn’t as good as it’s predecessor in my opinion. The start was slow, Prague was very City 17 depressing and the story was a bit hollow. I had fun playing it, but I would not have rated the same as a number of other news sites did.

My biggest disappointment though was buying an Xbox One. There is quite frankly, just no need for it if you have a PS4. Recore and Forza are unfortunately not enough for me to keep going back. I will see how long I keep it for, but my gut feel is that it will get traded with my PS4 when I finally decide I want a Pro or an inevtiable Pro-plus.

Oh yeah Final Fantasy XV and the Last Guardian became actual games! I have yet to play the latter, but FF was one of my favourite games of all year. Yeah the plot was a bit nonsensical at times, but I really enjoyed the whole experience. Well done to Squenix for finally getting it out the door!

I could go through all the games I have played, and it is hundreds. But that is not really the point I am making here.

Although the “real world” seems to be slowly falling apart around us we had a great year for games. Bring on 2017!

Share

Creating a Cloak Effect

It has been a while since I have done any type of tutorial or any technical related blog post, so I thought I would share the process of how I implemented a “cloak” effect on my character. Essentially in my game, I am adding a cloak skill and in order to visualize this to the player I want a sort of holographic semi-transparent cloak effect. Something magicy and Sci-Fi. So I jumped back into my shader coding.

If you need a quick refresh of the make up of shaders in Unity then here are a couple of previous posts (with horrendous typos that I should porbably sort):

Unity Shader Tutorial – A look at a basic surface shader

Unity Shader Tutorial – a look at a basic vertex and fragment shader

Cool, let’s do it.

First we start by creating a Surface Shader and then strip it back so it just performs diffuse lighting, a good starting point for all shader creation.

basicshader

Firstly in our properties section we are going to add… well… a new property

properties-capture

Which will expose the following “_DotProduct” float value to the editor that we add in our CG Program.

 

dotproduct

We also want to add a _MainTex property value pair into our shader.

We also want to change the tags.

tags

This will render the shader in the transparent rendering queue and will ignore projectors. If we want, as the player character is becoming invisible, we can also add the “ForceNoShadowCasting” tag that will mean the object does not cast shadows.

We also want to disable the expensive PBR in this shader and switch it out for Lambertion reflectance before telling the CG program this is a transparent shader and then finally disable the lighting. Wow that was a long sentence.

pragmas

The last thing we want to do before we actually jump into our surface function is change what actually gets run into the shader. In this case we want the world normal and view direction as well as what is already there.

inputstructure

Cool, now we whack this code in the surface function.

And we get this effect:

basic

On a sphere it looks pretty basic although it makes a cool atmosphere effect one, similar to the one I used in my seasonal globe:

What this shader is doing is actually showing the silhouette of the object. If I swap the circle out for something else and we move around it we can see the outline changes.

silhouette

After I tweaked the values a bit and applied it to my asset store model, here is what I got:

cloak

The gif doesn’t do it as much justice as in-game, but I actually think this is quite cool and that shader is cheaper than the previous refraction shader I was using.

I also had a little experiment for fun with my enemy model by adding a wave to all the verts and made what I am calling the “Demontor” shader

demontor

 

 

Share