Hunters
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 57 of 63.
Challenge
MediumNow 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
speedfield that the Inspector sets (3). - In
Start, find the player withGameObject.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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall