FatNick Makes a Game Part 7

Blimey! Has it really been a month since i last updated? Oops.

I’ve been busy. Well, not for the last couple of weeks or so, but up until then I was busy!

You see, as I was still hiding from the realities of having to sort out the vehicle physics, I opted to resolve the issues that stumped me last time.

First things first, the teleporting. Originally, my script moved the car from one trigger box to another, but this shifted every vehicle to exactly the same spot, which would never do. Instead, my revised script simply moves vehicles back by a set length on their current X axis. Cunning.

I also had issues getting unity steer to work. No idea why  for this one- just removing/re-adding the scripts seemed to get everything moving. Albeit a bit slowly. That was half an hour wasted.

At another crossroads, I decided to push on and make something that functions a bit more like a proper game. I wanted to make a playable looped demo that featured a couple of changing backgrounds and a proper scoring system. Eek.

makes game

 

After a quick trip to my favourite model repositories, I set about the easiest bits of the puzzle. Having grabbed some scenery models, I loaded them into the project as children of a global background object: By keeping them as children, I only had one object to swap out each time I wanted to change scenery. Easy peasy! With the city in place by default and a nice forest set up as a prefeb, everything looked like it should be easy peasy: Much like my teleport script, i thought it would be straightforward case of hitting the trigger, killing the old background and loading the new one in.

In fact, I even introduced a sneaky backup: To stop people reversing over the plane in order to change the background again and again, i had the trigger destroyed and then respawned when the player teleported back to the beginning. Cunning!

Unfortunately, this didn’t seem to quite work for me. Though the city would destroy and the forest would spawn, once you returned to the end it wouldn’t’ loop back to the city.

makes game

 

My first observation was that, when the background switch was destroyed and remade, the variable for the city was removed from the script. Odd. I didn’t think that the JS used in the game world would be active in the scripts as well. Just to be on the safe side, i removed the destruction/cloning loop to simplify things.

When the city still wouldn’t respawn, i was stumped…for a bit. I tried renaming the city several times before the penny finally sunk in. My city is ‘City1’ and my forest is ‘Pine1.’ After you’ve cloned them, however, the new objects are ‘City1 Clone’ and ‘Pine 1 Clone! This was why all references to city1 and pine1 weren’t working! Doh!

WIih the background changing, all that left to sort out was the score. Surprisingly, the hardest part was actually placing the text object into the game. The score itself is simply a public variable, modified by the speed of the vehicle. The faster you go, the more points you get (but you have to be doing at least 50 to get any points at all, slow coaches!)

So…a playable demo! How exciting. Please note, however, that this is completely unoptimized, and is based on Unity’s shiny new WebGL export functionality. This means it will rub in Chrome or Firefox without a plug in, but maybe a bit resource intensive! How high can you get the score before you inevitably crash?

Play Demo!

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.