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 :
- 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 :)