Hi,
I’m trying to make enemies follow the player, but also for them to collide with each other and other objects in my game. The “following” part works (I found some help for that here already), but as soon as I have multiple enemies, doesn’t matter where they’re placed, after some time chasing me they kind of all form into one, they overlap each other.
This is the code for following the player :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class follow : MonoBehaviour
{
public Transform Player;
public float MoveSpeed = 6f;
float MaxDist = 30f;
float MinDist = 5f;
void Update()
{
transform.LookAt(Player);
if (Vector3.Distance(transform.position, Player.position) >= MinDist)
{
transform.position += transform.forward * MoveSpeed * Time.deltaTime;
}
}
}
I’d really appreciate some help, I’ve been at this for quite some time.