- Home /
Script not recognising variable change?
void FixedUpdate(){
Vector3 newTargetPosition = target.position; //this is where the truck is
transform.LookAt(newTargetPosition); //turn to face target
transform.Translate(Vector3.forward Time.deltaTime forwardspeed); //move forward at forward speed
}
I'm new to this so I'm probably missing something rather obvious. The LookAt() function is meant to rotate the object each frame to track a moving object (called target). However it seems to consider the target.position variable to be the object's initial position every frame. As I have almost identical code in another script that DOES track the position of the same object, I am confused as to what is wrong!
Answer by Mike 3 · Sep 28, 2010 at 01:56 PM
The only thing I can think of is that it's not looking at the right object - have you tried removing the target and re-adding it?
:D Yes, that's the problem! Thanks! I knew it'd be something simple in front of my eyes.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074211im_/https://answers.unity.com/themes/thub/images/avi.jpg)