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 /
  • Help Room /
avatar image
0
Question by J-F · Jun 25, 2016 at 12:34 PM · rotationtransformtransform.rotation

Rotation snapping to 180 degrees with transform.rotation

I'm directly getting input from my Horizontal axis and assigning it to quaternion.x which is then set as the rotation to my object. but even the slightest change in the quaternion (less than 0.00001) snaps the rotation to 180 degrees on any axis. Here's my code:

         steer = Input.GetAxis("Horizontal");
         localRotation.x = steer;
         transform.rotation = localRotation;

Im trying to get the axis to directly controll the degrees of rotation on x axis.

Comment
Add comment · Show 3
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 JadeTheFlame · Jun 25, 2016 at 01:24 PM 0
Share

I have two solutions in $$anonymous$$d. I will do the extra work for you, just let me know one thing: Do you want this to rotate for as long as you hold the button down, or do you want this to have a max angle of rotation?

avatar image Mindmapfreak · Jun 25, 2016 at 02:13 PM 0
Share

Are you aware that the X-, Y-, Z-values of a quaternion do not correspond directly to euler-angles?

avatar image J-F · Jun 25, 2016 at 02:58 PM 1
Share

With maximum angles. I tried that with $$anonymous$$athf.clamp, but it changed nothing. im trying to copy a mobile device tilt axis to the angle of the game object with limits. THe tilt axis stuff is all worked out, its just the rotation itself that doesnt behave as expected.

1 Reply

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

Answer by JadeTheFlame · Jun 25, 2016 at 03:42 PM

Alright I have two answers for you.

First, is the one you asked for, using a maximum angle for your object. The drawback with using this one, is that you will not have control over how quickly your Input.GetAxis accellerates to 1 or -1.

     float maxAngle = 120;
     float steer;
 
     void FixedUpdate ()
     {
         Quaternion steer;
         steer = Quaternion.Euler(Input.GetAxis("Horizontal") * maxAngle, 0,0);
         transform.localRotation = steer;
     }

This second method simply rotates in the direction you are holding down, based on a fixed speed. Now, you can obviously alter this to your liking with an if statement to measure against the current rotation, so it has the potential to be a better solution if you need that rotation speed.

     float rotationSpeed = 10;
     float steer;
 
     void FixedUpdate()
     {
         steer += Input.GetAxis("Horizontal") * rotationSpeed;
         transform.localRotation = Quaternion.Euler(steer, 0, 0);
     }

Let me know how that goes for you. Good luck!

Comment
Add comment · Show 1 · 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 J-F · Jun 25, 2016 at 07:04 PM 0
Share

The first one works but its a bit jerky, i think i'll use somekind of treshold or lerp it to position. Anyways, Thanks for the help!

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

58 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

Related Questions

My rotation is not the same in inspector as it is in the scirpt 0 Answers

Cant stop object/ridgidbody from rotating 2 Answers

Rotation is broken 2 Answers

3D, Rotate gun towards mouse 0 Answers

Cannon rotation clamping 0 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