Hunters
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 60 of 71.
Challenge
MediumFill in Hunter so the hunters chase the player. Player is done; leave it as it is.
- Add
[SerializeField] private float speed = 3f;andprivate Transform player;. InStart(), setplayer = GameObject.FindWithTag("Player").transform;. - In
FixedUpdate(), takeplayer.position - rb.position, set its y to 0 and normalize it. - Set
rb.linearVelocityto its x and z timesspeed, keepingrb.linearVelocity.y.
Press Play and keep away. Then Check.
Try it yourself
using UnityEngine;
public class Hunter : MonoBehaviour
{
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Chase the player: find it by its tag, then run at it every physics step
}
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable WallPractice on your own: Unity playground