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 moghes · May 23, 2012 at 04:50 PM · rotationeuleranglesprint

Getting the rotation of an object, rotates the object!

Hello everyone! I have a globe that the user will rotate: Here's the code: function Update () {

 var horiz:float = Input.GetAxis("Horizontal"); 
 var vert:float = Input.GetAxis("Vertical");
 
  if(horiz > 0)
     transform.Rotate(Vector3(0,1,0), Space.Self);
 if(horiz < 0)
     transform.Rotate(Vector3(0,-1,0), Space.Self);    
 if(vert > 0)     
      transform.Rotate(Vector3(0,0,1), Space.World);
 if(vert < 0)    
     //print(transform.rotation.eulerAngles.z); 
      transform.Rotate(Vector3(0,0,-1), Space.World);     

}

So for the vertical rotation, I will put a limit(ex: 10 degrees max) and no limit (full rotation horizontally). I have used the print to check/get the rotation, but instead it rotates the globe without a keyboard input, as I run the game! someone tell me why?

Comment
Add comment · Show 4
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 torrente · May 23, 2012 at 05:00 PM 2
Share

Any chance you could post an exact copy of the file you are testing? I wrote up the code above and things were good for me. I can post my exact code as a solution should you need it. I removed your comment line to clean it up a bit.

avatar image moghes · May 23, 2012 at 05:18 PM 0
Share

I think I had syntex errors!

avatar image AchillesWF · May 23, 2012 at 05:18 PM 0
Share

$$anonymous$$y guess is you have the deadzone / sensitivity set wrong on the input device set as "Horizontal" and "Vertical". The GetAxis() return values may be returning a non-zero value which in your code would cause rotation.

avatar image moghes · May 23, 2012 at 05:23 PM 0
Share

That problem solved! but I can't put a limit for the rotation.. if(vert > 0) { print(transform.rotation.eulerAngles.z); if(transform.rotation.eulerAngles.z < 15); transform.Rotate(Vector3(0,0,1), Space.World); }

The print works! I see it printing and the value becomes > 15 but the rotation doesn't stop

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by torrente · May 23, 2012 at 06:22 PM

If you want to stop the rotation from going beyond a minimum/maximum, you can clamp it. For example:

 float rotationY; 
 float minimumY;
 float maximumY;
 
 rotationY += Input.GetAxis("Mouse Y");
 rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
 transform.localEulerAngles = new Vector3(-rotationY,0,0);

It's a little different than your design, but it will work. Assign the value, then clamp it. Here's the link to the unity page: mathf.clamp

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Fighter Plane Rotating Issues 1 Answer

Rotating a rigidbody on mouse click. 1 Answer

Rotation on Android vs. PC 0 Answers

2D animation : problem with rotation interpolation 1 Answer

trying to RotateAround an object around another object using mouse 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