Rotate towards target doesn't work properly (Quaternion.lerp)


I wrote a simple “Rotate towards target” script and was testing it but for some reason the object that I rotate ends up upside down.

Here is the code: (javascript)

#pragma strict

var target : Transform;
var strength = .5;
var targetRotation : Quaternion;
var str : float;
function Update () {
   targetRotation = Quaternion.LookRotation (target.position - transform.position);
   str = Mathf.Min (strength * Time.deltaTime, 1);
   transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, str);

and here is the picture of what is going wrong:
alt text

The ship needs to rotate with the front towards the planet in the background but ends up with the front down. I already changed the pivot/origin point in my 3d software (blender) but that doesn’t change a thing…

How do I fix this?

Thanks in advance,


For LookRotation() to work, the front of your object must face positive ‘z’ and up face positive ‘y’ when the rotation of the object is (0,0,0). This can be fixed in the modeling program, or you can use an empty game object as a parent and rotate the visible child object.