AI help

hey im trying to make an AI script but its not going well i cant really get my enemy to target me instead it just targets at 0,0,0

here is my code

var mobHealth = 50;
var hitMob = false;

var target : Transform;
var moveSpeed = 10;
var rotateSpeed = 10;


function Start()
{
	toon = gameObject.FindWithTag("Player");
	target = toon.transform;
}

function OnTriggerEnter(Hammer : Collider)
{
	if(Hammer.gameObject.tag == "Hit")
	{
		hitMob = true;
	}
}
function OnTriggerExit(Hammer : Collider)
{
	hitMob = false;
}

function Update ()
{
	myTransform = transform;
	
	if(hitMob == true  Input.GetButtonDown("Fire1"))
	{
		mobHealth -= 25;
		print(mobHealth);
	}
	if(mobHealth == 0)
	{
		Destroy(gameObject);
	}
	myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position -myTransform.position), rotateSpeed * Time.deltaTime);
	Debug.DrawLine(myTransform.position, target.position, Color.blue);
}

Thx

Your code works for me (though I suggest to move myTransform initialization in Start, it’s not needed to be in Update), I tried it on a cube against a capsule and the cube rotates correctly when the capsule is moved.

ahh now i see :slight_smile:

Found the mistake thx :slight_smile: