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 edwingohbh88 · Sep 19, 2016 at 02:21 AM · rotationscripting problemcamera rotatecamera rotationrotatearoundpivot

Unity Rotate Around and Orbit Question

Hi all,

I am making a scene with 3D cube on top e.g. (something like the scene view) top-right hand corner 3d cube, there are top,down,left,right cones buttons to allow user switch the view accordingly.

I am rotating a camera, that will rotates the cube similar to the scene view (cube you see in the top right hand corner) But my cube will be used during run-time.

However I am facing several problems with Rotating Around. I noticed when clicking on left and right buttons of the scene cube, it actually rotates the scene left and right around a point. When click on top/bottom view, it will go to "Top/Front" "Bottom/Back" view accordingly. And dragging right mouse button, the cube will also rotate to camera's rotation.

I did half of the following 1. Dragging right mouse button, cube will rotate according to camera rotation. 2. Rotate around left and right, however, it doesn't seems to work accordingly because I don't know where to stop the rotation e.g. should I stop at 90 degrees? Because the rotation can be applied anywhere e.g. the cube is with rotation of 90x,90y,20z, when i press left, it should Rotate Around and move towards the left view of the scene. 3. Top/Down rotation, I need some guidance on the implementation.

I am currently using Unity Rotate Around function, however it has some problems as I do not know where to stop the rotation.

I tried using Quarternion.Slerp(TOP_ROTATION/LEFT_ROTATION /FRONT_ROTATION) etc. But it is not so correct, because it does not Rotate Around a pivot point.

Anyone know how to properly code this camera rotation similar to what we have in the scene view? E.g. clicking left/right/top/bottom will go to the appropriate rotation (with rotate around pivot functionality).

My Code

         private float m_degreesPerSec = 90f;
         private Vector3 m_pivot = Vector3.zero;     
         private float m_totalRotationAngleSoFar = 0f;
         private bool m_startRotation = false;
         
         private void Update()
         {
         
       // problem about this is, it will always rotate 90 degree. e.g. if the cube is half tited, and I want it to rotate around a axis, I not sure how to get the desired rotated degrees
         if(m_totalRotationAngleSoFar  >= m_degreesPerSec )
         {
         m_startRotation = false;
         }
         
         if(m_startRotation )
         {
         
                     if (m_currentView == CubeViewMode.TOP)
                     {
                         MyCamera.transform.RotateAround (m_pivot, Vector3.right, m_degreesPerSec * Time.deltaTime );
                     }
                     else if (m_currentView == CubeViewMode.LEFT)
                     {
                         MyCamera.transform.RotateAround (m_pivot, Vector3.up, m_degreesPerSec * Time.deltaTime );
                     }
                     else if (m_currentView == CubeViewMode.RIGHT)
                     {
                         MyCamera.transform.RotateAround (m_pivot, Vector3.down, m_degreesPerSec * Time.deltaTime );
                     }
                     else if (m_currentView == CubeViewMode.BOTTOM)
                     {
                         MyCamera.transform.RotateAround (m_pivot, Vector3.left, m_degreesPerSec * Time.deltaTime );
                     }
 m_totalRotationAngleSoFar  += Time.deltaTime * m_degreesPerSec ;
         }
         }
         
         // When user clicks on top/right/left/bottom button besides the cube, this function will be call.
         public void StartRotation()
         {
         m_startRotation  = true;
         m_totalRotationAngleSoFar = 0f;
         }




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

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

78 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 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 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 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

View Matrix Camera rotation problem 0 Answers

How to make that the camera will not go through the walls? 1 Answer

First person camera- Limit X-axis rotation.,How to Limit Camera rotation on X-Axis 0 Answers

Issues with camera lookrotation - please help 1 Answer

MoveRotation stops working while player is moving 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