Final Project Post 2 - Player features, world interaction, interface and improvements

Player Features, World Interaction, Interface and Improvements

Introduction

After generating the world from blog post 1 the next logical step is creating a player that is able to move around within and interact with it. In order to show what steps were taken, this blog post has been split into four main sections as written in the title.

Player Features

Player features are somewhat minimal within this game. By default a player can only move and jump as well as place and destroy blocks. A minimalistic script was used to accomplish player movement by changing velocity in the forward direction of the player based on Unity's vertical input, if this value is negative then the player moves backwards, there is an attribute called speed that can be set in the editor to conrol how fast this movement is.

Player jumping took a little more tweaking. Jumping in the standard way of adding a force to the player Rigidbody did not quite feel right within the game because the time taken to reach the peak of the jump was the same as the time taken to fall from peak to the ground, and after a brief amount of research a solution was found through this video. Within this video he explains that often in games a playable character falls at a much faster rate than they jump, which has come to feel more natural to most gamers, and that this is easily corrected by adding an additional gravity force when the player's velocity falls below zero. This script also allows for the player to jump a little higher if they hold down the jump button.

World Interaction

World interaction involves the ability for the player to interact with the generated world by placing or destroying blocks. Placing a block involves raycasting from the centre of the screen/mouse position (which are the same in the case of this game since the cursor is locked to screen cenre) and using the normal of the block that is hit in order to find it's world space coordinates. These world space coordinates can be used to find the block that is adjacent to the normal in the world data array and changing this block from air into the block that is currently selected in the inventory (more information on the inventory can be found in the Interface section proceding this one). This is how this looks in code: (Input should not have been done here, but rather in the InputManager)
The full code as always can be found in a link at the end of this blog.
A note of interest about the UpdateChunkAt method is that a bug would occur if we simply updated the chunk that a block resides in when that block is in the edge of a chunk. Special attention and logic had to be added for any block that is on the edge of a chunk so that neighboring chunks would also be updated, else there may be unrendered sides of a cube visible to the player.
Removing a block requires the same process as above, but with slightly different offsets from the normal, and replacing any block hit with an air block then updating the chunk(s).

Interface

The interface also takes heavy inspiration from Minecraft, with a simple panel of boxes that can be scrolled between to select that point in the inventory. This was accomplished by creating a circular array to iterate between inventory spots and a sprite with a transparent center being moved to show which spot is selected. Inventory spots can have a variable that holds a byte value that represents a block that is generated within the World script. Unfortunately, due to time restraints, the group was unable to add the ability to collect blocks from the world, and instead decided to provide the player with the blocks necessary for building and combining various elements.

Improvements

Many of the animations for the game are placeholders which were intended to be replaced at a later stage in the development process. Again due to the time constraints a lot of these animations were never replaced. Some of the improvements that the group were able to add prior to the deadline were a main menu screen shown here:

and a legend within the game that can be accessed by pressing "L" in game, which shows the cube element combinations:

Project future

There was a huge amount of improvements that the group would have liked to implement such as more fluid movement, better animations and sound effects, the ability to collect items from within the world as well as spawning rarer elements within the rock layer and having the currently selected block in the inventory shown in the player's hand. The project currently also shares too many similarities with Minecraft, so the placeholder textures that were actually taken from Minecraft would need to be replaced.

Github link to project: https://github.com/KAdams01/GMDFinalProject
Youtube demonstration link:

Comments