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 Newbyscript · Oct 11, 2013 at 09:55 PM · quaternion

Limiting the X and Y of a rotation to 0

I cant figure out how to do it. Whenever i collide into another game object it sends me spinning on the x and y axis. My game is clamped on the y axis and that stays at 0. my controller for the player uses the Y rotation so this code below doesnt work because then i cant turn my player:

     void Update () {
 
         float yMovement = (turnSpeed * 20f * Time.deltaTime * Input.GetAxis("Horizontal"));
         
 
         transform.Rotate    (0,yMovement,0);
         transform.rotation = Quaternion.Euler(0,yMovement,0);
     }
 }
Comment
Add comment · Show 5
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 Newbyscript · Oct 11, 2013 at 09:56 PM 0
Share

what i need is to clamp the X and Z rotation to 0 but leave the Y free to move anywhere.

avatar image $$anonymous$$ · Oct 11, 2013 at 10:12 PM 0
Share

Tried $$anonymous$$athf.clamp?

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.Clamp.html

avatar image robertbu · Oct 11, 2013 at 10:23 PM 0
Share

I'm a bit puzzled here without the full picture. You write about collisions. Is your object a rigidbody, a character controller? If a rigidbody, have you tried to freeze x and z rotations in the constraints?

You can try the following line of code in place of lines 6 and 7:

 transform.up = Vector3.up;
avatar image Newbyscript · Oct 11, 2013 at 10:32 PM 0
Share

Yes i am using rigid bodies. freezing contraints doesnt work for me, not sure why. I forgot to say my above code fixes the problem, but then it doesnt let me turn left or right. I need some sort of code similar to this:

 transform.rotation = Quaternion.Euler(0,transform.rotation.y,0);
avatar image robertbu · Oct 11, 2013 at 11:18 PM 0
Share

You probably want this:

 transform.up = Vector3.up;
 transform.Rotate(0,y$$anonymous$$ovement,0);

This first straightens the player to align with the world 'Y', and then it does a relative rotation around the local 'Y' axis. You may need to do it in LateUpdate().

The line of code you outlined:

 transform.rotation = Quaternion.Euler(0,y$$anonymous$$ovement,0);

...will not work because it is an absolute rotation that will only vary based on your Input.GetAxis().

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Krey · Oct 11, 2013 at 11:06 PM

Do you want to register the collisions at all? If not, you could just avoid it entirely by using Unity's layer-based collision matrix: Layer-based Collision Matrix

That would allow you to selectively prevent other objects from colliding with the player, each other, etc...

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

16 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

Related Questions

Quaternion values at instantiation. 1 Answer

Rotate on 2 different axes 1 Answer

How to smoothly align an object to a surface, but only partially 2 Answers

Rotation 90.0001 and 1.001719 bugs! 1 Answer

Controlling the rotation of nested objects 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