top of page

Endless Road


Over the last fortnight, I have continued working on my Endless Driving game. I had a lot of trouble with many different aspects of creating this, getting stuck at many different stages.

To make the wheels, I originally tried to rotate cylinders, but they deformed instead of rolling, and wouldn't give a smooth ride. Next I tried to use spring joints, but that didn't work very well either. Eventually I used wheel colliders, which are a part of Unity. The wheel colliders worked very well at simulating wheels and suspension, however I couldn't change the variables (such as motor/wheel speed/reversing) directly from within the code. To change these values, I needed to create my own 'fake' copy of the wheel, change the variables on that wheel, and then say that the wheel on the car was the wheel I was just using.

To make the car upright all of the time, I lowered the centre of mass. Originally I did this by making an invisible GameObject (which everything else on the car was attached to) with a very large mass. I raised all of the car components so that the invisible mass would be especially low (underground). This didn't work, since Unity automatically places the centre of mass where the average area of the volume is. To counteract this, I instead put the invisible mass in the centre of the vehicle, and put the centre of mass in the same position (but lower) in code.

This worked fine, however once I changed the level, the car would flip onto it's front when the game started. This happened because when I set the position, I got the position of the invisible mass object on the car, then went below that and called that the mass. The problem was that I treated this like it was in WORLD space instead of LOCAL space. What I really did was put the mass downwards, but also as far away as the car was from the centre of the world. To fix this, I only needed to say that the centre of mass was downwards. Not to the invisible object and downwards.

When making the track spawn using tiles, I encountered another problem with world and local space. To stop the track from running back into itself, I did a check in the direction that the next tile would be placed. I did this so that if there was something there, it could choose a different section of the track instead. The problem was, the direction that I checked in was the direction of the tile if it started out facing forwards. If the track turned around and headed back in the direction that it came from, it would still check forwards instead of backwards. This lead to no tiles being valid and to the game crashing (even if I did eventually add some code to stop an infinite loop).

So far, I have the track generating, but there is still a fair bit of work that I will need to do to make this into more of a game. The track falls away after a certain amount of time and the player speeds up as time progresses to add challenge the longer the player survives.

Next week, I will focus on implementing fail states (game overs), and some system of tracking your score. I will also need to implement some music once it is finished.

bottom of page