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
1
Question by TempestInATeacup · Jun 10, 2015 at 06:43 PM · c#rotationquaternionplayer movement

resetting rotation on a single axis

I've created a script to rotate the camera on the z axis in order to allow the player to look up and down while holding the arrow keys down. I want to make it so that when they release the key, only the z axis rotation is reset, but the only script I've gotten to come close to working resets all axes, which is disorienting and not at all what I want.

This is the current script to reset rotation upon release of the key:

     if (rotatingVertically)
     {
         if (Input.GetKeyUp(KeyCode.UpArrow))
         {
             transform.rotation = Quaternion.identity;  //resets rotation but resets all axes
             rotatingVertically = false;
         }
         else if (Input.GetKeyUp(KeyCode.DownArrow)) //executes the first frame that the user releases the DownArrow
         {
             transform.rotation = Quaternion.identity;  //resets rotation but resets all axes
             rotatingVertically = false;
         }
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfdog · Jun 10, 2015 at 06:56 PM

This is what I would do:

 transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, 0);
Comment
Add comment · Show 2 · 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 TempestInATeacup · Jun 10, 2015 at 07:00 PM 0
Share

this produces the same result, and for some reason also prevents me from being able to look down after already looking up

avatar image triangle4studios TempestInATeacup · Jan 22, 2021 at 10:22 AM 0
Share

Quaternions are messy, or rather, our understanding of them often is. I recommend reading an ebook on them. Painful to read, but incredibly useful. This Free Ebook From Dartmouth University is an excellent start

avatar image
0

Answer by Dave-Carlile · Jun 10, 2015 at 06:57 PM

What Wolfdog said. Or if you know the reset direction, try Quaternion.SetLookRotation.

Comment
Add comment · 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

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

23 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Align Player to Regional Up Direction, Without Altering Look Direction Dramatically 0 Answers

Trouble with Camera Rotation Math 2 Answers

Weird shake when I try to rotate player according to Virtual Cameras rotation. 0 Answers

How can i rotate a object more than once (90 degrees)? 1 Answer


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