Quaternion.LookRotation() don't want to funtion properly?

Hello, I made a forum thread of the same name about this problem here http://forum.unity3d.com/threads/215727-Quaternion-LookRoation()-don-t-want-to-function-properly.

But I get no answers till now :frowning:

So, can you please tell me why does this LookRotation() thing don't want to "look" at the target?

P.S please read the forum topic to understand my problem as I don’t want to duplicate stuff. Thanks.

What happens here is that you are calculating a local direction from the Turrets perspective, and then rotates the turret to face that direction. The target will now have a new local direction and the turret rotates again. The local direction will change every time the turret rotates because your direction is calculated from the turrets rotation.

The slerp hides this by just smoothing all the directions it gets, but if you set the localrotation to the result from the LookRotation directly, the problem becomes apparent. The turret flips all over the place.

What you probably want is not to use the turrets local space but its parent local space which will not rotate each time:

transform.localRotation = Quaternion.LookRotation(transform.parent.InverseTransformDirection(target.position - transform.position));

Also for directions it is better to use the InverseTransformDirection.