I’m writing a script to level a drone’s tilt so it is flat. I have a quaternion for the start position I want to rotate to, and a vector for the current position. Since I only want to level the drone, not change its orientation, the rotationQuaternion (the target) uses the y coordinate that the drone currently has.
However at present the drone just snaps to an awkward 45 degree angle. How do I get smooth rotation to a level point while maintaining orientation?
The below code is in FixedUpdate()
Quaternion startRotation = new Quaternion(-0.5f, 0.5f, 0.5f, 0.5f);
Vector3 rotationQuaternion = new Vector3(startRotation.eulerAngles.x, transform.eulerAngles.y, startRotation.eulerAngles.z);
Vector3 currentPosition = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
transform.rotation = Quaternion.FromToRotation(currentPosition, rotationQuaternion);
Thanks for the help!