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 /
This question was closed Feb 18, 2015 at 08:23 PM by HexadimensionalerAlp for the following reason:

Solved it.

avatar image
0
Question by HexadimensionalerAlp · Feb 18, 2015 at 02:14 PM · c#rotationcamera rotate

Rotation doesn't stop after hitting bounds

I have a simple problem I just don't understand. I want to rotate my camera up and down (around x-axis) with a 0° and 90° as bounds. Here is the part of the script:

         if (Input.GetKey(KeyCode.W) && this.transform.localRotation.x > 0f) 
         {
             this.transform.Rotate(Vector3.left * 0.5f * rotateSpeed * Time.deltaTime);
         }
 
         if (Input.GetKey(KeyCode.S) && this.transform.rotation.x < 90f) 
         {
             this.transform.Rotate(Vector3.right * 0.5f * rotateSpeed * Time.deltaTime);
         }


When I rotate it with "W" it stops when rotation hits 0. When I rotate it with "S" it just keeps rotating untill I release "S". Any suggestions?

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 korbul · Feb 18, 2015 at 02:21 PM 0
Share

in the first if you are using localRotation.x in the second one you are using rotation.x Is this intended?

avatar image HexadimensionalerAlp · Feb 18, 2015 at 03:39 PM 0
Share

tried both does not matter

avatar image Glurth · Feb 18, 2015 at 07:27 PM 0
Share

tried both does not matter

you would get the same result UNLESS this object was the child of another rotated object.

2 Replies

  • Sort: 
avatar image
0

Answer by Glurth · Feb 18, 2015 at 03:45 PM

Don't think you want to check the rotation.x ... This is a Quaternion (x,y,z,w) value, NOT a rotation around an axis. To check rotation around an axis, you want to look at the EulerValues of the transform.rotation. http://docs.unity3d.com/ScriptReference/Transform-localEulerAngles.html

e.g (this.transform.localEulerAngles.x < 90f) or (this.transfor.rotation.eulerAngles.x) //the Quaternion class version

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 HexadimensionalerAlp · Feb 18, 2015 at 05:47 PM 0
Share

thanks but now it works for s but not for w. When I mix it it gets stuck when it stops at 0

avatar image Glurth · Feb 18, 2015 at 07:23 PM 0
Share

I think see what you mean, but I'm not really clear. What are you still using in your if statements now?

avatar image
0

Answer by HexadimensionalerAlp · Feb 18, 2015 at 08:22 PM

Here is my final code:

 if (Input.GetKey(KeyCode.W) && (cam.transform.localRotation.x > 0f && cam.transform.localRotation.x < 91f)) 
         {
             cam.transform.Rotate(Vector3.left * 0.5f * rotateSpeed * Time.deltaTime);
         }
 
         if (Input.GetKey(KeyCode.S) && (cam.transform.localEulerAngles.x < 90f || cam.transform.localEulerAngles.x > 350f)) 
         {
             cam.transform.Rotate(Vector3.right * 0.5f * rotateSpeed * Time.deltaTime);
         }

Works this way, the new bounds are because it doesn't stop at 0° but around 359° so I had to change that. But I don't know why it only works with mixing localEulerAngles and Rotation.

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 Glurth · Feb 18, 2015 at 08:59 PM 0
Share

well you are using X for both keys. I would suspect you'd want one of them to be another axis. see my edited answer above. Edit: oh, I see now.. the two keys are for back and forth on the same axis. ignore my comment & edit.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Roll a ball camera problem? 1 Answer

Multiple Cars not working 1 Answer

How to Change rotation while preserving local horizontal rotation 1 Answer

Limit camera RotateAround for an UAV game 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