Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mkleinSTS3D · May 18, 2016 at 07:27 AM · c#rotationrotate objectorbitmouseorbit

How do I combine Orbiting with mouse drag and with a button click?

Good day all!

I have like a model viewer setup and would like to know, how do I go about combining both mouse drag and click on a button to orbit/rotate the model?

This is what I have in my Update:

 if (Input.GetMouseButton(0))
         {
             if(isZoomedOut)
             {
                 x += Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
 
                 x = ClampAngle(x, xMinLimit, xMaxLimit);
 
                 Quaternion rotationX = Quaternion.Euler(x, 0f, 0f);
 
                 thisObjX.localRotation = Quaternion.Slerp(thisObjX.localRotation, rotationX, dampSpeed * Time.deltaTime);
             }
             else
             {
                 xZoom += Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
 
                 xZoom = ClampAngle(xZoom, xMinLimit, xMaxLimit);
 
                 Quaternion rotationX = Quaternion.Euler(xZoom, 0f, 0f);
 
                 zoomObjX.localRotation = Quaternion.Slerp(zoomObjX.localRotation, rotationX, dampSpeed * Time.deltaTime);
             }
         }
 
         if (Input.GetMouseButton(0))
         {
             if(isZoomedOut)
             {
                 y += -Input.GetAxis("Mouse X") * ySpeed * 0.02f;
 
                 y = ClampAngle(y, yMinLimit, yMaxLimit);
 
                 Quaternion rotationY = Quaternion.Euler(0f, y, 0f);
 
                 thisObjY.localRotation = Quaternion.Slerp(thisObjY.localRotation, rotationY, dampSpeed * Time.deltaTime);
             }
             else
             {
                 yZoom += -Input.GetAxis("Mouse X") * ySpeed * 0.02f;
 
                 yZoom = ClampAngle(yZoom, yMinLimit, yMaxLimit);
 
                 Quaternion rotationY = Quaternion.Euler(0f, yZoom, 0f);
 
                 zoomObjY.localRotation = Quaternion.Slerp(zoomObjY.localRotation, rotationY, dampSpeed * Time.deltaTime);
             }
         }

My orbit (left/right/up/down) buttons set a bool witch triggers the orbit in the Update like:

 if (isOrbitUp)
         {
             thisObjX.localRotation = thisObjX.localRotation;
 
             thisObjX.Rotate(Time.deltaTime * 20f, 0f, 0f, Space.World);
         }

This is what my hierarchy looks like:alt text

How do I make these 2 methods work together?

hierarchy.png (3.8 kB)
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 SonicScrew12 · May 19, 2016 at 04:46 AM 0
Share

What do you mean by "mouse drag and button click"? Is it a GUI button you're clicking, or is it a key on the keyboard you're clicking?

avatar image Mikilo · May 19, 2016 at 09:08 AM 0
Share

Hello!

First of all, you need to save the rotation and the position of the mouse when you click down with your mouse.

When the mouse move, you apply the delta from the initial mouse position to the rotation!

This way the job is done!

Good luck dude!

0 Replies

· Add your reply
  • Sort: 

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

Flip over an object (smooth transition) 3 Answers

Why the player is not rotating and moving at the same time ? 0 Answers

Rotate camera to object on sphere 1 Answer

problem after rotate an object 1 Answer

How can I make it so cameraCenter Roatates 90 degrees smoohly after swipe! 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