I’m making a game where the player is being chased by numerous enemy cars who are operated by AI. I have this script below to handle to AI. It works fine with just one enemy in the scene but when I spawn multiple, they all combine into one car and get very glitchy. How can I fix this? Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AI : MonoBehaviour
{
public Transform Player;
int MoveSpeed = 15;
int MaxDist = 10;
int MinDist = 5;
void Update()
{
transform.LookAt(Player);
if (Vector3.Distance(transform.position, Player.position) >= MinDist)
{
transform.position += transform.forward * MoveSpeed * Time.deltaTime;
if (Vector3.Distance(transform.position, Player.position) <= MaxDist)
{
//Saved for later when I add attacking
}
}
}
}