Hello, right now I am in the final final steps of my game and my last problem I can't seem to fix. Currently I have an enemy that constantly chases the player and when it touches the player it restarts the level, this is all working perfectly right now except that when I go around a corner the enemy then usually starts rotating towards the player but not chasing, and sometimes backing away.
Heres my script:
var target : Transform;
var speed: float;
function Update () {
if (target == null && GameObject.FindWithTag("Player"))
target = GameObject.FindWithTag("Player").transform;
// Rotate towards target
var targetPoint = target.position;
targetPoint.y = transform.position.y;
var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
transform.Translate (0,0,speed*Time.deltaTime);
ResetY();
}
function ResetY () {
transform.rotation.x = 0.0;
transform.rotation.z = 0.0;
transform.position.y = 14.5;
}
Does anyone know why this might be happening? Could adding a raycast and stop chasing when the player is around a corner work?
Thanks.