- Home /
Question by
Computoguy · Aug 10, 2011 at 09:48 PM ·
javascripttransformrotategunlookat
LookAt Problem
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!
Comment
Answer by AMDAndrew · Oct 27, 2012 at 02:55 PM
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);
}
Your answer
Follow this Question
Related Questions
hoe to rotate a AI as a animation 1 Answer
How to prevent Z axis rotation ? 1 Answer
LookAt transform plus a y value 1 Answer
hide hand / gun smooth, not use animation ??? 0 Answers
making one object a parent of another via javascript 2 Answers