var player : GameObject;
var speed : float = 1;
function Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
if (!player)
Debug.Log ("ERROR could not find Player!");
}
function Update()
{
if (!player)
return;
var distance = Vector3.Distance( player.transform.position, transform.position);
if ( distance < 100 )
{
Debug.Log ("player is close");
var delta = player.transform.position - transform.position;
delta.Normalize();
var moveSpeed = speed * Time.deltaTime;
transform.position = transform.position + (delta * moveSpeed);
}
else
{
Debug.Log("not close yet " + distance);
}
}
I'm using this as my movement script, and I've made a GameObject using blender and put it in a prefab. The problem is that when I use the LookAt() function (even if I put it in a separate script), the enemy I've created gives me its side rather than its front, and it always stays a large distance away from my Controller. Is there any function I can use, or any code block that would make the enemy turn that extra 90 degrees to look at my character? Even better is there some way I can fix this from the inspector itself? I've tried rotating the prefab but that doesn't work either.
I got the code from another question on this website but for the life of me I can't remember the URL of that question.
↧