- Home /
Quaternion.LookRotation() doesn't look down
So i have a turret that i want to point towards a certain target (for now, my mouse), and i got it working by simply doing this:
pitchObject.LookAt(target);
pitchObject.Rotate(new Vector3(-90, 90, 0));
This is the result: link
Now, the problem is that i don't want to have to apply it to the turret directly, i want to have it in a quaternion so that i can use Quaternion.Lerp(), so i tried this:
Vector3 direction = target - transform.position;
Quaternion quat = Quaternion.LookRotation(direction);
quat *= Quaternion.Euler(-90, 90, 0);
pitchObject.rotation = quat;
But then suddenly it can no longer look down, as seen here.
Would someone be able to explain to me why this happens? And maybe if i'm doing something else wrong. :)
Answer by NameWasTaken · Mar 26, 2018 at 09:23 PM
Realized what was wrong, i was doing the direction from the bottom of the turret, not the barrels of it, therefore the target was always at the same level or above.
Answer by NoMoneys · Mar 26, 2018 at 06:44 PM
By doing quat *= Quaternion.Euler(-90,90,0); you are only adding the two together. Your problem seems to be with the X-axis, so my guess is that you are clamping the X-axis to -90, because if target never becomes negative, then the X-axis will never get below -90.
I removed that line completely and now it looks like this: link