I made this code for my ai:
var size=10;
var Enemy:GameObject;
var colidindo=false;
function Update () {
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, -up * size, Color.green);
if(Physics.Raycast(transform.position, -up, hit, size)){
colidindo=true;
desvia();
Debug.Log("Hit");
}
else
{
colidindo=false;
Debug.Log("Walking");
}
}
function desvia()
{
if(colidindo==true){
Enemy.transform.Rotate(Vector3(0,1,0));
}
else
{
}
}
it makes the enemy divert any obstacle however when it divert one time,he’s running like a madman.How can I correct this?