Hello.
I have a slight problem (well, kinda big) when it comes to rotating my Camera. It will not stop rotating and continues to rotate even after turning a full 360 along the X axis
The only thing I wish to accomplish is rotating the Camera by 90 degrees so it looks towards the ground.
IEnumerator Rotate_GodMode_Camera()
{
// This function will explicitly deal with the rotation of the Camera.
while (_godMode)
{
if (Camera.main.transform.rotation.x != 90f)
{
Camera.main.transform.Rotate(new Vector3(90 * Time.deltaTime, 0, 0)); //Rotate the Camera by 90 degrees every second
yield return new WaitForSeconds(.001f);
}
else if (Camera.main.transform.rotation.x >= 90f)
{
break;
}
}
}
So when the input is detected, it starts this Coroutine.
I plan on adding a lot more to this once this basic part is figured out, and a coroutine is the way that I need to go to accomplish what I want.
I managed to get this to work if I use a generic i int variable and ++ after 1 second of WaitForSeconds, but is there a reason why this seems to be ignoring conditions?
Man I wasn't even looking at rotation, I just saw != and was like "Nope, floats can't not != something". :S You can use rotation.eulerAngles.x instead of rotation.x to get your rotation values. See [the page on Quaternions][1] (rotation is a Quaternion; don't try to understand what they are unless you Really Love Math A Lot, just how to use them) [1]: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html
– LoiusAlthough reading individual elements of eulerAngles often fails, since there's more than one valid way to convert quaternions to eulerAngles (e.g., <0, 0, 0> is the same as <180, 180, 180>). It's better to lerp the rotation from one to another instead of trying to check conditions. Also don't do things like "yield return new WaitForSeconds(.001f);", just yield a frame instead. See the Rotation function [here][1]. [1]: http://wiki.unity3d.com/index.php?title=MoveObject
– Eric5h5