Question about AI in MMORPG

Hi guys! I’m currently making a Co-op Zombie Apocalypse Survival Game.

But there’s on problem. The Zombie follow just the newest GameObject with “Player” Tag. not the old one :confused: Is there any way to fix it?

Btw Here’s the Script i tried:

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour
{
    public int minRange;
    public bool follow;
    public float moveSpeed;
    public float rotationSpeed;
    private Transform myTransform;
    public Transform player;

    void Start()
    {
        myTransform = transform;
		player = null;
    }

    void Update ()
    {
	   if(Vector3.Distance(GameObject.FindWithTag("Player").transform.position, myTransform.position) < minRange)
        {
			player = GameObject.FindWithTag("Player").transform;
            follow=true;
        }else{
			follow=false;
		}

        if(follow && player != null)
        {
            myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(player.position - myTransform.position), rotationSpeed * Time.deltaTime);
            myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
        }
    }
}

Any Ideas :)?

You can move your FindWithTag command to the Start method and save it in a variable. This way you’re zombie will aways follow the same player. But the really cool thing to do here is to use GameObject.FindGameObjectsWithTag to get all players and selected the nearest or the weakest player, so you can start to develop an AI.