Rotate tank turret using quaternions
Iv'e spent ages trying to get this to work correctly, i'm fully aware that my code is wrong for what I want to do, but I'm not sure what to add to fix it. For a flat plane, the turret rotates correctly, however, as soon as the hull moves over any sort of pitch or roll angle, the turret stays fixed in those 2 axis relative to the world. I have tried getting the rotation of the hull and using it in the target rotation vector for the otherwise constant values (x, y) but while this almost works, it actually doesn't. code:
Vector3 rot = new Vector3(-90, 0, camera_Holder.transform.eulerAngles.y);
Quaternion targetRotation = Quaternion.Euler(rot);
this.transform.eulerAngles = Quaternion.RotateTowards(this.transform.rotation, targetRotation, 0.25f).eulerAngles;
im using .Lerp because it gives a nice rotational transition between the current and desired rotation. My other option that i know will work is using transform.Rotate, but i don't really want to use this as its going to over complicate the calculations, .Lerp does it all for me, i just need to give it the correct numbers, which i guess i'm not.