Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Lairinus · Feb 18, 2013 at 06:24 PM · c#camerarotation

Rotation seems to pass through condition checks

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Feb 18, 2013 at 07:48 PM

Transform.rotation is a 4D quaternion, which does not use degrees (everything is normalized), nor do the x/y/z elements directly correspond to x/y/z axes.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Loius · Feb 18, 2013 at 08:04 PM 0
Share

$$anonymous$$an 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 ins$$anonymous$$d of rotation.x to get your rotation values. See the page on Quaternions (rotation is a Quaternion; don't try to understand what they are unless you Really Love $$anonymous$$ath A Lot, just how to use them)

avatar image Eric5h5 · Feb 18, 2013 at 08:13 PM 0
Share

Although 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 ins$$anonymous$$d of trying to check conditions. Also don't do things like "yield return new WaitForSeconds(.001f);", just yield a frame ins$$anonymous$$d. See the Rotation function here.

avatar image Lairinus · Feb 18, 2013 at 08:17 PM 0
Share

Okay, thanks for the information guys!

I am still in the process of figuring out exactly what to do (as this is a lot of information) so I'll post anything else in about an hour (probably year) when I kind-of understand what to do lol

Gonna start playing around with Eulers and Lerps though. **

Figured it out. (at the moment) my final code is:

         IEnumerator Rotate_God$$anonymous$$ode_Camera()
         {
         /*
          * This function will explicitly deal with the rotation of the Camera.
          */
             while (_god$$anonymous$$ode)
             {
                 if (Camera.main.transform.rotation.x < 80f)//Need to fix this; will check the Quaternions of both objects.
                 {
                     Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, _rtsCameraPoint.transform.rotation, Time.deltaTime);
                     
                     yield return new WaitForSeconds(Time.deltaTime);
                 }
                 else if (Camera.main.transform.rotation.x >= 90f) //Need to fix this as well, but again, won't be a problem
                 {
                     break;                
                 }
             }
         }

So what I ended up doing was basing my rotation problem around a Lerp which rotates it over a period of time. I got the initial rotation from the Camera itself, and I got the projected rotation (to rotation) from the empty object I created called _rtsCameraPoint.

What I will do in the future is create a variable to hold the Quaternion value of the rotation of the empty object, but for now everything is working very well!

(I know that the code has some serious flaws, namely the conditions. Gonna fix that up now but thought I'd drop my answer here before I did so)

Thanks guys!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

how do i make first person character rotate left and right along with camera? 0 Answers

How to move camera up and down 1 Answer

Rotate camera smoothly down and back up 1 Answer

How can I turn the direction of bicycle in Unity? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges