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 SVGK · Feb 26, 2014 at 12:31 PM · roation

How do I rotate on Z axis within a set of constraints?.

i'm trying to make something that can be rotated, but within a set of constraints, in my case, the Z axis.

however, any attempts made so far failed badly, here is my script, the context is that the W button is meant to tilt the platform upwards, but also only be able to go so far, the same is true for S, except it tilts backwards:

         if (Input.GetKey (KeyCode.W) && platform.transform.rotation.eulerAngles.z <= 25f)
         {
             platform.Rotate(0f, 0f, 2f);
         }

         if (Input.GetKey (KeyCode.S) && platform.transform.rotation.eulerAngles.z >=330f)
         {
             platform.Rotate(0f, 0f, -2f);
         }

what i want is for the rotation to go from 25 to 15 and then 5, then 0, then 359, then 350 and 330, that direction, and from 330 to 359 to 10 to 20 to 25 with the W button.

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 Ashutosh8126 · Feb 26, 2014 at 12:43 PM

After the two ifs you can use.. platform.eulerAngles = new Vector3(platform.eulerAngles.x,platform.eulerAngles.y,Mathf.Clamp(platform.eulerAngles.z,25,330));

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 SVGK · Feb 26, 2014 at 03:41 PM 0
Share

hm, i've tried this now, it doesn't quite work, i mean, it does let me rotate and it does indeed clamp the platform, but the problem is that it does so in the wrong way.

see, this rotation is meant to be more like tilting back and forth, however, it requires me to rotate it all the way upside down and back to get from one freeze point to the other, which is very backwards and quite literally the opposite way it should work.

i'm looking now at how the rotation changes, and it seems that what i want is for the rotation to go from 25 to 15 and then 5, then 0, then 359, then 350 and 330, that direction, is that possible to do?.

avatar image
0

Answer by Wolfram · Feb 26, 2014 at 04:35 PM

Your code for W should be fine, does it not work as expected?

The code for S also uses = here instead, as you don't want the angle to become smaller than 330. Querying something.eulerAngles will always return angles between 0 and 360.

Note also that transform.rotation.eulerAngles queries World coordinates, while the default settings for Rotate() modify local coordinates (see docs). You actually might want to use transform.localRotation.eulerAngles instead, or transform.localEulerAngles for short.

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 SVGK · Feb 26, 2014 at 05:18 PM 0
Share

the W code seems to work now that i put that back in, but the S code doesn't, even with your suggested change, or the localEulerAngles.

looking at the way the rotation is working now, it seems that what i want is for the rotation to go from 25 to 15 and then 5, then 0, then 359, then 350 and 330, that direction, and from 330 to 359 to 10 to 20 to 25 with the W button.

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

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

Adding Rotation & Fire Rate to an Object Pool 0 Answers

Rotating, moving and keep on going with constant velocity in direction of click 1 Answer

how to move the camera using the mouse scroll in all direction? 0 Answers

Rotating a Gameobject In Three Axis Unity 3 Answers

Lock rotation of tank barrel 2 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