Fatnick Makes a Game Part 5

(For Fatnick makes a game Part 4, click here)

Hello everyone,

Since my last update a lot of stuff has changed!

Having completed my test track, I’ve decided to go in more of an arcade-driven direction for the actual game. So let’s make a game!

To start with, I’ve dropped my car into a new scene and created a road for it. Oh, I’ve also dropped in a coach for you to crash into and a script with will make you explode if you hit either the coach or the crash barriers.  Hurrah!

make game

A coach! It’s like the M25

So how did I do it? Well, having already created my prefab for the car, I simply dropped it into a scene with a plane 100m long and about four lanes wide. That having been done, I dropped smaller planes for the lane markings and a couple of long blocks for the crash barriers. Simple.

From there, I locked the car’s rotation on the Y and Z axis, preventing any rolling and allowing for some slightly more ridiculous handling.

With the car and the barrier having been created, it was time to drop in a basic crash script I started with this and got:

//Basic collision detection checking for car and wall, swapping model for debris

function OnCollisionEnter(thecollision : Collision)

{

if(thecollision.gameObject.name==”Walls”)

{

Instantiate(Debris, transform.position, transform.rotation);

Destroy(gameObject);

}

else if(thecollision.gameObject.name==”Large1″)

{

Instantiate(Debris, transform.position, transform.rotation);

Destroy(gameObject);

}

}

This script will only kill you, currently, if you crash into the walls or my coach. I have a feeling this is possibly a bad approach generally, but I intend to have a strictly limited about of things that can kill you – so I don’t mind adding them individually.

make game

Here’s my debris – it’s about the same size as the car.

 

As for the ‘debris’ (the remains of the car) and ‘Large1’ (my coach), I created the debris from a collection of MR2-sized cubes with an internal sphere collider, and my large obstacle took the form of a royalty-free model of a coach (predictably on the wrong axis as before –  but nothing adding to a parent object didn’t solve.)

MR2 and Coach

So, with the car, object and collision script ready to go, did anything work? Nope! Predictably my shiny new script wouldn’t work at all. Why? I have absolutely no idea. For some reason the ‘if’ clauses weren’t working, so the car would explode into blocks the second it spawned on the road. Erk.

Weirdly, however, all it took to resolve this was saving and loading the next morning. Again, I have absolutely no idea why that worked, but I’m definitely not complaining! So now, I had an MR2, a stationary coach, and a script which made the car explode if it hit either the walls or the coach.

But now, of course,  I had to make the coach move. I have to admit, I wasn’t sure about the best way of going about this. I was thinking of editing the script I’d used to control the MR2, but then I came upon Unity Steer. As it contains a number of scripts which also handle route finding etc, I thought this would no only help get things moving, but may well help out down the line if I wanted to include lane changes etc. My Coach now moves forward thanks to the rather splendid Autonomous Vehicle script.

make-game

Wheeee

 

So now I have my first 5 seconds of gameplay. Sorry, that wasn’t fantastically entertaining was it? Sorry. I’ll try and be more interesting next time AND have something interactive!

(Part 6)

One Reply to “Fatnick Makes a Game Part 5”

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