I have a few objects that I am animating but I am having trouble with the following code. With the first animation I made, this code seems to work fine for making the object face the direction it is moving in. But when I change the animation to have the object go on a different course, it faces in the wrong directions. Is this code no good for this or is there probably some other issue messing things up?
var oldPosition : Vector3;
function Update(){ transform.LookAt(transform.position + oldPosition, Vector3.up);
oldPosition = transform.position;
}