The Product College early application deadline is Oct 31 - Apply Now

Adding the Goal

Adding the Goal

October 9, 2010
Expand

Project: Learn How to Build Drift

Our game loop is nearly complete but we need a goal for our player to reach!

Before we add the goal, let’s make our level look a little more the way we want it. For our first level, we can just make a channel for our player to go down. If you build it out of Planes, you’ll be able to see through from the back, which will be helpful when you want to add more elements to your levels later.

We made a long hallway

So that we could use it later, we made our tube of Planes into a Prefab.

Let’s also make our level look a little prettier. If you remember the original Drift, it had these neat orange shadows.

To do this, go into the Lighting Window and set the Ambient Color to orange.

The ambient color is now orange...

Now your lights will cast orange shadows!

...so now the shadows are orange!

It’s a little difficult to see clearly now, so we’ve added a few more Directional Lights, made them all white, and given them different rotations and intensities.

Add some more directional lights to your level.

When you added lights, you may have thought to yourself, "wait a gosh darn moment! My directional lights aren't casting shadows from the backs of the planes!" That's right. Planes are one-sided in Unity, meaning that things like lighting and collisions can only hit them in the direction opposite to the normal. This is also why you can see through Planes if you look at them from behind -- which can make positioning Planes for the first time a bit tricky!

Our one-sided planes allow in light from behind them

Creating the goal

Now let’s create a goal for the Player to reach. When you reach it, for now, have it restart the scene, but log a message.

Create the Goal.

We created our Goal as a Sphere tagged with a new tag we made, Goal. Then we changed our Player’s OnCollisionEnter method to the following:

void OnCollisionEnter(Collision col) {

  if (col.gameObject.CompareTag("Goal")) {
    Debug.Log("WIN!");
  }

  SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}

To make our Goal stand out more, we made it use a green emissive material and put a green haloed light on it.

We made our goal green to stand out

We made our goal green to stand out

We also increased our Player’s movementSpeed to 20, since it felt like we were moving a little too slowly.

Feedback

If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations across the USA and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more