Monday, 22 January 2018

Mining, few tweaks


The next step is to implement a mining system allowing players to mine rocks. This feature, unlike the previous, is going to be quite challenging. I have been looking around on the internet for help sources and have found very little, therefore a lot of the implementation will come from experimentation.

I am going to treat the ore blocks like enemies to the Player, this will make the implementation easier and I will use ‘health’ as a way of determining the rock’s state. I will incorporate this with the work that I have just done for Unit 603 – Using AI in Computer Games, to which I created a working state machine system. These states can help me to determine the physical state of each rock as it gets damaged, and I’m hoping to be able to use these states to change the sprite.

EDIT - 27/01/2018: Update!
I have implemented the mining part of the system. There is currently no interaction, but there is collision being detected. The solution I found was to fire out a Ray-cast in the direction that the player is facing (determined by movement input). The hit data of the Ray-cast is stored in a variable, which I am currently using to log the name of the object hit to the console. One problem that I have come across is that I’m not sure how to deal with the animations. I believe that I would need to create a totally new set of animations for if the player is walking and mining at the same time. To combat this, as it looks strange, I have made it so that the Player can only mine when not moving (mining interrupts movement).
I also added a nice sky background to the level that I made in GIMP. It was created using a simple gradient of blue to white. Furthermore, the camera now finds the Player in the scene at game start and follows him around. There’s a bit of smoothing time, the camera ‘lags’ behind the Player, I’ve done this because I find that it’s easier on the eyes if the player isn’t always in the centre of the screen. For the duration of the next week, I will be working on implementing the second part to the mining: applying damage to the rocks.

Monday, 8 January 2018

First level, Player Character and Animations


Figure 1
 The first step for this week’s goal was to think of a way to implement my level. At first, I thought that my only option would be to drag and drop each individual sprite into the level. Not only would this have been very time consuming, but it would have also meant that editing the level would have been a lot of effort. This is when I stumbled upon a great tutorial by YouTube user quill18creates. This method involves creating a single sprite, with individual pixels representing the colour of the object which will be placed in world space. An array is made storing all 32-bit colour values (RGB 0 – 255) and it searches the sprite for those colours. These colours each correspond to their own prefab, which will be instantiated, depending where the colour was on the sprite. The sprite that I have created is shown below (fig. 1):
Figure 2
I created the sprite with colours that correspond to their respective ore colours, that way it’s easier to see which ores will spawn at which locations.

Figure 3
To make this work, I had to import all my sprites, creates prefabs out of them (a prefabricated object which acts like a mould / template) and then drag them into the array elements in the Unity inspector. For each of the ores I added a box collider so that it can detect collisions. This allows the player to stand on them and will be used when the mining mechanic is implemented.

Once the level was in place it was time to implement the Player Character and animations. This will enable me to be able to walk around my newly implemented level and open doors to some of the more juicer programming. Implementing the character was easy using the animation and animator windows within Unity.



The animator tool uses ‘States’ and ‘Parameters’ to work. States are the current form or standing that the object is in, while the parameters are conditions which help to transition between those states. I found that these states work better if there is a ‘base’ state – by which I mean a state which is default, has no animations attached to it, and can transition to any state depending on whether the parameters have been met, for this I called it ‘Player_Idle’. After creating the ‘Player_Walk’ animation (fig. 3), I simply then dragged this animation into the animator window and added the parameter of ‘isIdle’, which will transition to the walk state if it’s false. The final step was to add the code for the movement and voila! Our player can now move around the level!

Download the game and Project Files!

The project files along with any additional documentation are located in this folder on my Google Drive. To download the game please down...