Need help with AI in multiplayer

I’m working on a coop horror game. I attached this script to an enemy, so it will follow the player:

var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
 
function Start () 
{

}

function Update () 
{
    transform.LookAt(Player);
    transform.position += transform.forward*MoveSpeed*Time.deltaTime;
}

Now the problem is: when I start the game and connect to the server, the enemy won’t follow the player. Instead the enemy moves to the player’s spawn. Does anyone know how to fix this?

(Sorry if my English isn’t that good, I’m Dutch)

Hello :smiley: Here are the things you can try:

Try to look at and move towards the player by identifying the player by tag.

(Someone else already said this but) Make sure that the player variable has the player instead of the player spawn assigned.

It could be a multiplayer glitch. Do you Network.Instatiate the players or are they there in the scene? I suggest trying to Network.Instantiating the players instead of putting them in the scene.

Also, I would make a range system so that when one player gets closer to AI than the other, it follows that player. Since you only set it to follow player, it will only follow one player.

Hope this helps :smiley:

(I am a beginner-intermediate at multiplayer in Unity3D)