Project Goblin - Grid & Movement

New Game!

I have been prototyping some mechanics and systems for my new game that’s in the works. I do not have a title for the game as of yet, but I have been working on my design document for the game and it is time to get into the engine for some work! Here is some of the first systems that I have worked on so far. I will detail more content in a later blog post.

Grid System

I am designing the game on a grid system where obstacles, hazards, pickups, and the player will be placed on. I needed my grid to be able to toggle my obstacles on and off on the grid (obstacles are shown as a red squares on the grid) to stop the player from moving on that position, and then allowing them to move at runtime. I created a simple toggle to test this out and you can see the results in the video below. It works great!

 
 

In the video, I am testing if the player detects that grid space as an obstacle (red square), and if it is indeed an obstacle, then the player is not able to move through that space on the grid. I am using a key press to test the toggle of changing that grid location to an obstacle and back.

Also, on my grid I am restricting the player to the bounds of the grid so the player will not be able to travel outside the designated areas. This will come in handy for the level design and keeping the player within bounds.

In the code snippet below, this is how I create my grid with specific variables that allow me to resize the grid before the level has been ran. I wanted a way for the grid to be resizable in the editor so that different levels may be different sizes if need be.

Player Movement

How I decided to design the players movement is by 1 meter increments in any direction that the player chooses to move. For example, if the player pressed down the W key one time then the player will move 1 meter up. This functionality works for Up, right, down, and left exactly the same way. I also wanted the player to be able to move quickly from one grid position to another while holding down a key. So when the player holds down a key they will continuously move 1 meter at a time in that keys direction. I made a function called Move that takes in a direction the player will move towards and does a couple checks before it handles any player movement.

If it was cleared to move, then I will run a coroutine to handle moving the player to the target position, which is 1 meter in the chosen direction. This coroutine will do a check for the distance between the start position and the target position. If the player is less than a small amount away from the target, it will make that players new position the target position. Then this coroutine will update a couple variables to make sure movement is complete to be able to move once again.

Challenges I faced

Some of the challenges I faced while working on these two systems are

  • Getting the grid to contain a unwalkable cell

  • Getting the player to move one cell at a time smoothly.

I know I could have taken an easier route for using the unity’s tile map, but I wanted to make my own grid system from scratch and learn how to handle the needs as I build my game. I was iterating through various ways to handle detecting if a cell is an obstacle, if there is an object not on the cell that is an obstacle and what the player does when trying to move in the direction of an obstacle. What I ended up doing was adding a way to check both ways for obstacles. I have a simple raycast checking for obstacles being placed in the level at random, and I also have a check on my grid system which will be the grid allowing any player movement in the game. I felt it was necessary to have both ways to check since I never know if an object is going to be placed in a level that is not on my grid. This gives me a little more flexibility when designing my levels.

The player movement system I reworked a couple different ways after finishing my grid system, and the results I ended up with were to move from one center of a cell to another. That ended up feeling much better than just moving 1 meter in a direction not utilizing the actual grid system at all. This one took a few iterations, to get feeling right, but I believe that I landed on a sweet spot for the player movement and is easily editable for speeds, and distance of cells to move.

Conclusion

I currently have the grid system to be able to be expanded on if I need to add more functionality to it. Right now getting the player moving on the grid while keeping them within the bounds works great for the scope of this project. I am also happy with how scalable the grid can be on either direction of the axes and how I can toggle obstacles on and off of a grid location at runtime to affect the player movement.

I have learned quite a bit while figuring out how to make a grid based system and moving the player on a grid. I am excited to work on more features for this game and start showcasing some more progress updates in the future!

Ryan Beattie

A game designer and developer that has a passion for creating fun experiences.

https://RyanBeattie.net
Previous
Previous

Spawner, an Ability, and some Pickups

Next
Next

Project Rider