Animated Object facing forward problems

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;

}

I don't think that will give you the results you're after. If you want the object to face in the direction it's moving, try something like this instead:

Vector3 v = transform.position - oldPosition;
transform.LookAt(transform.position + v);

This will orient the object in the same direction as its last movement delta.