Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Hiyek · Nov 28, 2017 at 06:46 AM · camerarotationcamera rotateplayorientation

[Solved :D] Camera auto turns 180° from its init position on Play (Animated GIF Included!)


Exactly as the title says: I set my camera to face a certain direction upon start and it turns (yaw) exactly 180° from that once I press play. In my simple mouselook script, I tried making a Start() function setting these exact initial Euler vector coords for testing, and it would start correctly, then snap the other direction as soon as a frame goes by.

(Animated gif of the issue at the bottom of this post)


This leads me to believe it has something to do with the line in my Rotation Application section of Update (there is no Start now, as that was just for testing; the initial values of this line are not set in the variable declarations; hence why I've only included the pertinent Update function):


transform.rotation = Quaternion.Euler(currentPitch, currentYaw, 0);


   /* UPDATE (CALLED ONCE EVERY FRAME) */
 
     void Update () {
 
 
             // Pitch w/ Inversion Code
 
         if (Input.GetKeyDown("i")){ //If 'i' key is pressed
             inverted = !inverted;   //invert if not inverted (default), and vice-versa
         }
 
 
             if (inverted)
             {
                 targetPitchRot += Input.GetAxis("Mouse Y") * lookSens; //inverted
             }
             else
             {
                 targetPitchRot -= Input.GetAxis("Mouse Y") * lookSens; //not inverted
             }
 
         
             
             
             // Yaw
 
         targetYawRot += Input.GetAxis("Mouse X") * lookSens;
 
 
 
 
 
             // Smoothing
 
         currentPitch = Mathf.SmoothDamp(currentPitch, targetPitchRot, ref lookSmoothXVel, lookSmoothDamp);
         currentYaw = Mathf.SmoothDamp(currentYaw, targetYawRot, ref lookSmoothYVel, lookSmoothDamp);
 
 
 
 
 
             // Rotation Application        
 
         transform.rotation = Quaternion.Euler(currentPitch, currentYaw, 0);
         
 
 
 
 
     }           /* ENDUPDATE. */



Unity Issue _PT001


unityissue-pt001.gif (482.8 kB)
Comment
Add comment · Show 2
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 Hellium · Nov 28, 2017 at 04:46 PM 1
Share

You have to set the values of current$$anonymous$$ch and currentYawin a Start function.

Try something like :

 void Start()
 {
      current$$anonymous$$ch = transform.eulerAngles.x ;
      currentYaw= transform.eulerAngles.y ;
 }
avatar image Hiyek Hellium · Nov 28, 2017 at 05:18 PM 0
Share

Yeah I was thinking along the same lines, since the compiler arrives at the rotation orientation at the end of Update (and by this point, if the player doesn't touch the mouse, the values will be (0,0,0), so that all makes sense) and isn't really told what to do before then. However, I've tried your code, I've tried manually setting currentYaw=130; (which is how I got it to pause for a second before the smoothing in my "bug" post) and still the same thing over and over. Like I said, changing it locally worked (even though it shouldn't have lol I was not thinking clearly) until I saved and booted the project back up.

$$anonymous$$aybe my compiler had a glimpse into empathy for human logic and I killed it when I shut down Unity xD

Edit: & I gotta say a huge THAN$$anonymous$$ YOU for even responding! TWICE!! You're awesome. Just to have someone else's input has eased my frustration of going insane for the past 8-9 hours now.

Oh.. actually 10 hours. just checked lmao

1 Reply

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

Answer by Hellium · Nov 28, 2017 at 05:27 PM

My bad, you have to assign the values to targetPitchRot and targetYawRot too :

 void Start()
  {
       currentPitch = targetPitchRot = transform.eulerAngles.x ;
       currentYaw = targetYawRot = transform.eulerAngles.y ;
  }
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 Hiyek · Nov 28, 2017 at 05:36 PM 0
Share

I was just about to say at this point I'm probably going to feel really dumb when I finally figure it out, but I don't think I would've. Thank you so so so so so so so so so so so so so so so so so sososo muchhhhh dude!! IT WOR$$anonymous$$SSSSSS!!!! :D

Edit*:If you'd like to repost that last comment as an answer, I'll gladly accept it. Thank you so much again I have half the $$anonymous$$d to weep at this conclusion of one long & stressful night lol

avatar image Hellium Hiyek · Nov 28, 2017 at 05:48 PM 1
Share

Glad you will sleep peacefully tonight ! ;D

avatar image Hiyek Hellium · Nov 29, 2017 at 11:09 AM 0
Share

That I did, good sir :p

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

133 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix weird camera rotation? 0 Answers

Rotate an object around another on input 0 Answers

maximum angle for camera 0 Answers

Best way to rotate child and parent game objects in different axes without the rotation going crazy or glitchy? 1 Answer

Set camera rotation around point in 2D 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