AI random target

Hello everyone , i have code like this :

  var Hedef : Transform; // hedef means the Target
  var Gorusmesafe = 1000; // Gorusmesafe means the distance which the AI can see
  var sword:GameObject; 
  var runningspeed : float = 0.08;

  function Update () 
  {
    if (Hedef && Follow()) 
    {
      var HedefRotation = Quaternion.LookRotation(Hedef.position - transform.position, Vector3.up);
      transform.rotation = Quaternion.Slerp(transform.rotation,  HedefRotation , Time.deltaTime * 2.0);
    }
    var targets : GameObject[] = GameObject.FindGameObjectsWithTag("ZulDurak");
    var targetNumber : int = Random.Range(0,targets.length - 1);
    Hedef = targets[targetNumber].transform;

  }

  function Follow() 
  {

    if(Vector3.Distance(transform.position, Hedef.position) > Gorusmesafe )
    {
      print("too far");
      return false;
    }

    if (Vector3.Distance(transform.position,Hedef.position ) < Gorusmesafe ) 
    {
      transform.Translate(Vector3.forward * runningspeed);
    }

    if (Vector3.Distance(transform.position,Hedef.position) < 5 )
    {
      Attack();
    }

    if (Vector3.Distance(transform.position,Hedef.position ) < 1 ) 
    {
      transform.Translate(Vector3.forward * -1 * Time.deltaTime);
    }

    if (Vector3.Distance(sword.transform.position,Hedef.position ) < 1 ) 
    {

      Hedef.transform.Translate(Vector3.forward * -4 * Time.deltaTime);

    }
    var hit : RaycastHit;

    if(Physics.Linecast(transform.position,Hedef.position,hit))
    {
      if (carpma.collider.gameObject.tag !="Character")
      {

      }
      else 
      {

      }
    }
    return true;
  }

  function Attack()

  {

    sword.animation.Play("Tam Vurma");

  }

This is the AI code from war game which is with sword shield etc.

But when i launch the game :

  1. Problem : In 1 vs 1 it's cool , ally AI finds the enemy AI and enemy AI finds ally AI then attack each other and when they collide and their GorusMesafe is less then 1 like written in the code they force each other. But when 3 or more AI's come together , i think because of that " transform.Translate(Vector3.forward * -1 * Time.deltaTime); " thing they start flying in the air like this :

http://i1104.hizliresim.com/2011/4/22/11632.png

How can i solve this ?

2.Problem : When i first start the game , ally and enemy AI's select their targets randomly for example A character selects C character. But when i close the game and open again , the A character selects AGAIN the C character , they alwasy select the same character after 1 random selection , how can i solve these problems , please someone help and explain clearly :)

Greetings , please help :)

I have a game with lots of enemies pushing about as well. Putting this code into the update function of the bad guys seemed to fix the jumping problem.

function Update()
{
    //Move about first

    //Zero upward movement
    transform.position.y = 0;       
}

Next what you need to do is "seed" the random number generator. You see random number generators are not truly "random". The sequence of number they produce is based on a seed. I'm getting different random numbers each time I start up my projects (so maybe someone else could tell us why you are getting the same numbers each startup) but you could still try this

function Start()
{
    Random.seed = Time.time;
}

first , thank you for answer.

I tried that position.y but when i do this they are not flying around this is good but they all come together and fps reduces to 4 or 5 , i also don't want them to come together like in the photo , i thought i can prevent this by making their selection random , so i put the code you gave me right into the script but it didn't work :/