LookAt Problem (26658)

I’ve run into another problem. I’ve got it, so that a gun or turret looks at my character. Here’s the script:

var LookAtTarget:Transform;

function Update () {
transform.LookAt(LookAtTarget);
}

I’ve set this JavaScript to the turret, which is then set to my character. However, instead of rotating, it literally moves itself to the middle of nowhere and just faces forward. Gah. Help ASAPP!

You have to assing in the Inspector the target or do this :

var LookAtTarget:Transform;
var target : GameObject;

function Awake(){
target = GameObject.FindWithTag("Player");
LookAtTarget = target.transform
}

function Update () {
transform.LookAt(LookAtTarget);
}