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 Elit3d · Apr 09, 2015 at 12:18 PM · rotationobjectslidereulerangles4.6

Object Rotation Sliders

So currently I have an object rotation script that is connected to sliders. Only problem is im not sure how to move it in one direction then make it go back to the original position based on where slider is, I probably will have to store max min and current but not sure how to implement:

 public void W_KeyRotate(int wControl){
             targetRotation *= Quaternion.Euler(mainCamera.transform.right * rotationAmount);
     }
 
 
     private void Snap()
     {
         Vector3 vec = targetRotation.eulerAngles;
         vec.x = Mathf.Round(vec.x / rotationAmount) * rotationAmount;
         vec.y = Mathf.Round(vec.y / rotationAmount) * rotationAmount;
         vec.z = Mathf.Round(vec.z / rotationAmount) * rotationAmount;
         targetRotation.eulerAngles = vec;
     }

thats just part of the code

Comment
Add comment · Show 2
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 Nerevar · Apr 09, 2015 at 12:41 PM 0
Share

Well,

If I understand right you have 3 sliders and you would like that each of them control the rotation angle of the x/y/z axes.

and you want to rotate the camera?

avatar image Elit3d · Apr 09, 2015 at 12:56 PM 0
Share

No not the camera and yes xyz

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by termway · Apr 09, 2015 at 04:08 PM

If your sliders value is between 0 and 359, the code below should do the rotation of your object with slider value.

 public Slider[] sliders = new Slider[3];//Put your sliders here
 
 void Start()
 {
     sliders[0].value = transform.localEulerAngles.x;
     sliders[1].value = transform.localEulerAngles.y;
     sliders[2].value = transform.localEulerAngles.z;
 
     foreach(Slider slider in sliders)
         slider.onValueChanged.AddListener(Snap);
 }
 
 private void Snap(float value)
 {
     transform.localEulerAngles = new Vector3(
         sliders[0].value,
         sliders[1].value,
         sliders[2].value
     );
 }

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

19 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

Related Questions

Rotating Object on its Local World Axis 4 Answers

My Obstacle Rotations Are Not Correct 0 Answers

Simulating a Fidget Spinner 1 Answer

ConfigurableJoint - angular positions (rotation) problem 1 Answer

How do I rotate a circle of objects so that a specific object is in front of the camera? 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