top of page

Car Game

Car game was a hobby project of mine. I decided to stop working on it as I realised that I didn't have neither the time nor resources to make it the game I wanted it to be. For now, it has been put on ice, but I might return to this project one day.

Gameplay

The goal of the game is to collect as many points as possible, either by being the first one in goal, or by collecting the spheres placed throughout the level.

The game is split into two different gameplay modes: at the start of the game, and after each of the four semi-goals placed along the level, each player may add one piece of track to the level. Once every player has added their part, the players race on the track, competing with each other for the points and getting to the semi-goal first. Once a player reaches the semi-goal, the racing phase stops and the gameplay loop restarts. Once a player has reached the 4th and final goal, the player with the most points win!

Design

My process for coming up with the idea and how I wanted to develop it further.

Core concept

My initial idea came from wanting to create a somewhat silly, racing couch play game, and I became inspired by games like 'Unrailed!' and 'Ultimate chicken horse' to create one where the player could interact with the level to reach the goal. 

Ultimate Chicken Horse

Creating the challenge

I quickly came to the idea that I wanted players to build the level as they played, however in the earlier stages, the plan was that each car would be a team of two players. One player would place roadparts in front of the cars in real time, while the other player would drive the car.

       In the end, I decided against this, as I wanted players to build cool and satisfying roads to utilize to win the game, instead of having a second player continuously throw out pieces in front of them. The two-player-per-car game mode would also create much shorter games, which I didn't want.

       Finally, the 'build mode' in between the racing created a nice change of pace to the game, instead of constantly being very fast paced.

Future plans & additions

In the current version of the game, there are only three types of road parts that the player gets one randomly from. In the final product, I wanted the player to be able to have a choice of what to place; get a random road part, get a random hazard (something that would be a difficulty for other players as well as yourself if you got close, I never got to create any of the hazards), or to move an already existing road part or hazard on the field.

       I also wanted to create a lot more different types of road parts, some that weren't so standard as the ones in the game, both so that the parts actually would create a decisive change to the level, and to really make players consider what the optimal spot to place it would be. 

Level design: the first part of this level got a level design, which players had to consider and play around.

Level design

Finally, I did consider to add more of a level design to the game. My initial thought was that the player would build the entire level and that there would be nothing (except for the platform with the points and the goals on them) on the level. The plan was also to allow players to place a set amount of pieces each and then the race would start. However, I realised that this turned out to be more of a chore than anything, especially since the road parts you could add at this point were so insignificant. When playtesting, the players just put out parts as much as possible to get some kind of road over to the goal and to the points and then went to the 'driving mode', instead of considering where to place their parts. 

       To fix this, I added a slight level to the game, which you can see in the gameplay video. The level gave some roadblocks that prevented the players from driving straight, and it also had a way from the players' spawn to the goal. Now, instead of just adding pieces left and right, it was up to the players to figure out how they could add pieces to the level to gain an advantage, which made the game a lot more both tactical and enjoyable.

Code

I have done all code in the game, except for the steering of the car. Here, I'll go through some of the code that I struggled with or code

that turned out really well. 

Creating blocks

I started by creating a system to place the 'blocks', or road parts into the world.

       First of, I created a very quick grid system, where three for loops, one for each axis, created a grid which I then would be able to move my blocks within.

As is right now, each player gets one of three random parts when the previous player has placed their block. 

       I used a list of gameobjects to add the different parts and a random range going from 0 to the count of the list to get a random block, so I could easily add new blocks whenever I created one without having to change a single line of code.

Placing blocks

To make sure blocks couldn't be placed on top of each other, I had to save each block's position in the grid in a list. Each 'base block', the block that moves around in the video above, has a transform of their own. A block made up of multiple base blocks has multiple transforms. When a player tries to place a block, a loop goes through all the transforms of the block and compares them to the position of blocks already placed. If there aren't any duplicates in position, the block is placed and the position of the transforms are added to the list. If there are duplicates however, the player cannot place a block there.

Adding players to the game based on their input device

This one I struggled with a lot. I wanted one player to be able to join by the keyboard and other players to be able to join by controller, but I didn't necessarily want keyboard to always be player one, as some player might now want to use the keyboard overall.

       The other issue this caused me was that I needed to save the information of how many players there were and which player had which controller in one scene, and then be able to access that information in the actual game scene. This means that any player could pick up any controller and use it as any number, instead of always assigning "controller 1" to steer "car 1".

This is the start menu. Any player, regardless of controller or keyboard can join at any time and be the next free slot.

I started by checking the input from the different devices by assigning them a number of their own, which I then sent into the "PlayerJoin" function.

Once an input device has entered the 'PlayerJoin' function (and that device hasn't already been added), the integer amountOfPlayers increases by one. The list playerController also adds the number of the just added device. 

We then start the game scene and move the integer amountOfPlayers to a static int and the list of ints playerController to the static list controllerNr

Once in the game scene, our game manager turns on gameobjects called 'carSet', which is the car as well as the platform it starts on, equal to the size of playerCount. It also creates unique settings for the cameras based on the amount of cars (so for two players it is split in half, for three there are two smaller cameras and one bigger etc.), and finally places the carSets on their position. This position is based on a Vector3 that is unique for just that amount of players (for example p1Position2Players), which allows the position of the different cars to be different depending on how many players there are in the game. 

One player game view

Two player game view

Finally, to make the different players able to move their respective car (so that the player that joined as number three will controll the third car), I used unity's input manager system and changed between different names based on which player's turn it was.

       In the image to the right, you can see the input axis called "zAxisP", which there are four different suffixes of. By changing the suffixes by moving through the list with the integer playerTurn (increases byt

Back

bottom of page