Hi, I’m looking for a version of “RotateAround” that doesn’t modify the transform itself, but would allow me to get back the Quaternion from applying the “RotateAround” transformation to the game object, without affecting the transform itself.
Basically I’m using my mouse’s X position to rotate the camera, and I want to clamp the rotation between [-maxAngle, maxAngle]. In my code right now, I’m rotating an object, then checking if I rotated it too far, then rotating it back. It’s functionally “correct” but I think there exists a helper function somewhere that makes this easier.
float horizontal = Input.GetAxis ("Mouse X") * rotationSpeed;
float currentlyRotated = Quaternion.Angle(transform.rotation, Quaternion.AngleAxis(0, Vector3.up));
// I only want to apply this transformation if I don't translate too far on the Y axis.
transform.RotateAround (transform.position, Vector3.up, horizontal);
// HACK, for now if rotating by horizontal is too far, reverse the rotation.
float cr2 = Quaternion.Angle(transform.rotation, Quaternion.AngleAxis(0, Vector3.up));
if (cr2 > maxAngle) {
transform.RotateAround (transform.position, Vector3.up, -horizontal);
}
As you can see, this approach is indirect and has too many branches to be good for performance. It’s also just confusing from my point of view without the comments.
Thanks!