Need help with javascript AI

hello, I took an AI script from an other topic around here and I saw that the “zombies” merge together and that is unwanted, I added a function “Stay away” but I don’t know what to do.

If you have any other ideas, feel free to speak of them.

var player : GameObject; 

var otherzombie : GameObject;

var speed : float=6f;

var range : float=15f;

var hitRange : float=6f;

var separationRange : float=3;

var enemyDamage : float=10f;

var rotationSpeed : float=5f;

var damageTimer : float=0f;

var delta : Vector3;

var distance;

var distancefromzombie;

function Start()

{

player = GameObject.FindGameObjectWithTag("1Player");

}

function Update()

{

//calculate the enemy's distance from player and do a check to see if we should 

    //progress then call the necessary methods

distance = Vector3.Distance(transform.position, otherzombie.transform.position);

if(distance<=range)

{	

	MoveTowards();

	RotateTowards();

	AttackPlayer();

}



distancefromzombie = Vector3.Distance(transform.position, player.transform.position);

if(distancefromzombie<=separationRange)

{

    StayAway();

}

}

function MoveTowards()

{

delta = player.transform.position - transform.position;

delta.Normalize();

delta.y = 0;

if(distance<=(hitRange/1.5))

{

	return;

}

var moveSpeed = speed * Time.deltaTime;

transform.position = transform.position + (delta * moveSpeed);

}

function RotateTowards()

{

transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(delta), rotationSpeed);

transform.rotation = Quaternion.Euler(0, transform.eulerAngles.y, 0);

}

function AttackPlayer()

{

damageTimer+=Time.deltaTime;

if (distance < hitRange && damageTimer>=1.5)

{

	damageTimer=0f;

	player.SendMessageUpwards

	("ApplyDamage", enemyDamage, SendMessageOptions.DontRequireReceiver);

}

}

function StayAway()

{

}

Regards

Furdak

If you want to have some sort of good path finding have a look at the A* algorithm. Also check out raycasting. They need to have some sort of detection of each other and detect obstacles (I assume). The way I see it you copied and pasted a random script for AI, it didn't work and now you want someone to fix it, this is not Unity-Hire-A-Coder, check out the forums for teaming up with an experienced programmer.