Cloaked Knight – Game Design

Introduction

Okay so for my last prototype I wanted to try the last type of 2D games, a platformer, however it kind of got the same treatment as galactic dragon, being mostly for the code than the art, which is why the art makes sense together but isn’t much. However there is animation now which I will move first actually to get it out the way and so we can get onto the coding after as it is technically related but also not

Game Link

Just in case you want to see what this is all about:

https://budbot5002.itch.io/cloaked-knight

Animation

Okay so basically Unity has the animator which when you get multiple images and number them after each other (so 01, 02 exedra) and drag them together onto the canvas they will merge into a animation, which can then be controlled through the animator. This then lets you affect how the animations change on an object, so for this we have the player that swaps between an idle and a walking left and right animation, for this we use a variable that changes in the code for when they move a direction or stop. This variable is then used in transitions between the animations in the animator so if it is a 1 it will go to walk left or if it is a 0 it will go to idle exedra.

Tile Pallete

Okay so this is also technically part of unity so I’ll explain it here too, basically you can use the tile palette to draw the inputted tiles on a grid in the layout, so I have a palette of all my tiles which I can just used the brush in the tile palette to pretty much just draw my little level I have, then this ground acts as one item instead of multiple different ones which is very helpful for organizing and setting collision. Which we need as we don’t want the player falling through the floor, so we just put a tile map collider which is basically a collider made specifically for tile maps so we don’t have problems like gaps in between the tiles and such.

Required

Movement

Okay so now we have the tile palette sorted we need the allow the player to actually move, so to do this we need a script that basically works like our space invaders, taking the left and right inputs and moving the correct way, but also triggering the animations depending on what it should be for that of course, leading to this:

And like I said before it is just taking keys and moving but now we are taking the movement on horizontal as that is left and right and if it is more than 0 it is moving right, if it is less it is moving left and if it is 0 it is idle, setting the walkState accordingly for these as well.

Jumping

Okay so now we need the actual platformer ability of platforming, so we need to be able to jump which basically is moving the player up at a certain speed in a burst pretty much as the player already has simulated gravity so that does the falling part for us. Leading to this:

Okay so it had a bit more but I’ll explain, basically incase we wanted a character to have multiple jumps in a platformer we would need this total jumps part as it keeps track of the jumps it can do and the number it has, alos keeping track of if it has touched the ground through a collider on the feet of the player. This then basically says if it is touching the ground, if yes reset the jumps, if not you are jumping and so leave the number of jumps

Enemies

Okay so since this is more of a concept I just have small little slimes which you jump on, so we need the player to be able to jump on them and kill them, and die on touching them. For this it actually links into the spikes we make later so for now lets just make the player able to kill them with this:

So this actually uses the collider on the feet from the jumping script to check for the slime, if it finds it it kills the slime and launches the player up basically, however I also just made the slime bounce up abit and fall through the floor too because, well I can. This allows for the player to not actually touch it, so we can just link the death part to if they touch the player and the kill part to the feet collider as it is actually further out than the player’s

Spike/Enemy

Okay so spikes kill on hit, no matter what, meaning yes the enemies hit from the dies but the spikes can’t be killed, how do we do this? Well we just don’t give them this enemy script and the player will land on them and die, which is why we separated them. Leading to us making the other missing script for dying of this:

And yes it is as simple as it looks, if touch player, kill player, done. We don’t need anything else really so yeah lets just leave it here as I’ve also already explained why it is separate and how it works between spikes and enemies and such

Camera

Okay so you might have noticed one key flaw, the camera just stays fixed, before this wasn’t a problem with the others as we binded the player to it but for this we want to move the camera with the player, which again is a case of it is hard and so Unity made a code snippet purely to fix this problem. With the use of this it basically just follows the given object at a given speed, allowing for you to off set it from the player when moving or just having it super fast and fixed if you want to be boring, leading to this:

So like explained before, it looks for the object called Player and follows it, however we have a fail safe (ooo fancy) which basically checks for the player being there, if it is there it follows, if not it just does nothing, resulting in no crash. Another note, we set its z to -10, why? Because if not it goes on the same z and leads to us not being able to see the level anymore as it needs to be behind stuff to see it, which is why.

Conclusion

Overall even though this game is simple I feel it does a good job for setting the framework for future platformers if I wish to go into them further. I also liked how simple it was as after Invasive Squirrels and how complicated that was a nice simple project was just what I needed

Leave a comment

Your email address will not be published. Required fields are marked *