Zombie not pointing at player?

I have a zombie script that moves the zombie towards the player, but it’s gliding over the terrain sideways, depending on where the player is. I’ve tried getting it to work, but I need help fixing the problem.

Here is my current zombie script:

#pragma strict

var player : GameObject;
var speed : float = 1;
var Health : int = 3;
var rotateSpeed = 90.0;

function Start () {
	player = GameObject.Find("Player");

	if (!player) {
		Debug.LogError("Could not find Player!");
	}
}

function Update() {
	var moveSpeed = speed * Time.deltaTime;

	if (!player) return;

	var distance = Vector3.Distance( player.transform.position, transform.position);

	if ( distance < 60 ) {
		Debug.Log ("A zombie is close");

		var delta = player.transform.position - transform.position;
		delta.Normalize();

		transform.position = transform.position + (delta * moveSpeed);
	}
	var horiz : float = Input.GetAxis("Horizontal");
	transform.Rotate(Vector3(0,horiz * rotateSpeed * Time.deltaTime,0));
}

Any help is appreciated :slight_smile:

Can the zombie be controlled by Input? You’ve got an Input.GetAxis in the last few lines. Other than that, I suggest trying to invert the delta because the returned direction might be pointing away from the player.

var delta = transform.position - player.transform.position;