Hello, I have been hunting and have found a script that works in short, I would prefer if my enemy would avoid walls but I could easily work around this. My problem is that the enemy will not come close enough to my player to look like it has actually attacked me. It is almost like there is a cushion around my player but I have checked all colliders and they are no way near each other when the enemy pushed back:
var enemy : Transform;
var player: GameObject;
var dir: Vector3;
var speed: float;
var observed: boolean;
var sightDistance: int;
function Update () {
if(Vector3.Distance(enemy.position, transform.position)< sightDistance){
transform.LookAt(enemy);
if (observed){
dir = player.transform.position - transform.position;
dir = dir.normalized;
transform.Translate(dir * speed, Space.World);
}
else {
transform.eulerAngles.y = Mathf.PingPong(Time.time*20,90) -45;
}
}
}
function OnTriggerEnter(other:Collider) {
if(player) observed =true;
}
function OnCollisionEnter(collision : Collision)
{
if(collision.collider.gameObject.name == "arrow(Clone)")
{
Destroy(this);
}
}
Any help on the matter would be great!
Cheers,
Matt