Quaternion (look)rotation issue (gimbal lock?)
Hey folks!
I want my weapon to aim precisely at the target of my free-moving crosshairs. Similar solution to Metroid Prime (Wii), Operation Flashpoint, Elite Force 2.
But I had a problem with Quaternion. When the value on the x-axis approaches 90 degrees, the object on the z-axis begins to rotate up to 180 degrees. I’ve seen this cause a lot of people a problem and if I understand correctly, it’s a Gimbal Lock problem, but I haven’t seen a case like mine.
I tried Transporm.LookAt, Quaternion.LookRotation and Quaternion.RotateTowards, but they all have the same problem. Maybe someone has an idea how I could solve this problem or bridge it? I hope someone can help me because I really like this type of mouse control and don’t want to sacrifice it.
Thanks!
Quaternions don't have gimbal lock (that's why we use them). LookRotation (or LookAt) should perfectly aim +z at the target, with +y the most "up" it can be. Thatt means ai$$anonymous$$g up and a little forward, to a little backwards, will flip the spin (so +y is always the most "up").
Thanks. In the meantime, I also realized that it really isn’t a gimbal lock. However, I have found the solution elsewhere since then. The problem was that I simply used Vector.up as the y direction target instead of the parent object (fixed) transform.up.
So it works well now and thanks to your answer I already know what was the logical "problem" in the background.