Menu
CoddyTech

Hunters

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 57 of 63.

challenge icon

Challenge

Medium

Now the hunters. Two stand in the arena, tagged Hunter, each with a Rigidbody and the Hunter script. Keep the player from the last lesson, and fill in Hunter:

  • A speed field that the Inspector sets (3).
  • In Start, find the player with GameObject.FindWithTag("Player") and keep its Transform. The next lesson makes hunters from a prefab while the game runs, and a prefab's field cannot hold an object from the scene, so each hunter finds the player itself.
  • Every physics step, set the hunter's velocity toward the player across the ground at speed, keeping its y velocity.

Press Play and keep away from them, then Check.

Try it yourself

using UnityEngine;

public class Hunter : MonoBehaviour
{
    // A later lesson fills this in: hunters that chase the player.
}

All lessons in Physics and Gameplay