Week 5 | Session 2 - Enemies Follow the Player - April 21, 2020

Tutorial

·

Beginner

·

+10XP

·

60 mins

·

(32)

Unity Technologies

Week 5 | Session 2 - Enemies Follow the Player - April 21, 2020

The player can roll around to its heart’s content… but it has no purpose. In this live session, we fill that purpose by creating an enemy to challenge the player! First we will give the enemy a texture of your choice, then give it the ability to bounce the player away... potentially knocking them off the cliff. Lastly, we will let the enemy chase the player around the island and spawn in random positions.

Languages available:

1. Overview

This is the same content covered in Lesson 4.2 in the independent Create with Code Course.

What you will make:

  • A textured and spherical enemy will spawn on the island at start, in a random location determined by a custom function. It will chase the player around the island, bouncing them off the edge if they get too close.

What you will learn:

  • Apply Physics Materials to make game objects bouncy
  • Normalize vectors to point the enemy in the direction of the player
  • Randomly spawn with Random.Range on two axes
  • Write more advanced custom functions and variables to make your code clean and professional

2. Before you Begin

To participate in this session and follow along, you need:

  • Unity 2018.4 installed
  • An up-to-date project open in Unity:
    • If you have followed along with us this week and have your own project ready, you are good to go!
    • You can also download the instructor's up-to-date project and import it (If you don't know how to import a project, you can read how here)

If this is your first Create with Code live learning session, you can catch up by:

  1. Following along with the recordings of our previous live learning sessions
  2. Completing the same lessons in the independent Create with Code Course

*Note - it is not necessary for you to catch up, but it is recommended for an ideal learning experience.

3. Recorded Live Session - 21st April - 9am PST

If you missed this session, you can catch up with the video below.

4. Recorded Live Session - 21st April - 5pm PST

If you missed this session, you can catch up with the video below.

5. Next Steps

Get caught up:

If you were not able to finish the session along with the instructors, you can catch up by:

  1. Re-watching this recorded session when it is posted in Step 3 above at 3am PT (10am UCT) the morning after this session's date
  2. Picking up where you left off in Lesson 4.2 of the independent Create with Code Course

Bonus Challenges:

  • Experiment with new features (after making a backup)
    • Program a bit of Artificial Intelligence so that enemies attempt to stop when they’re near an edge
    • Add a new more difficult type of enemy and randomly select which enemy is spawned
  • Look ahead to the next lesson
    • If you want to go ahead and preview what we'll be covering in the next session, you can give it a try in Lesson 4.3 of the independent Create with Code Course.

Complete this tutorial