Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 hdtvee · Apr 20, 2020 at 10:22 PM · rotationrotation axislocalrotation

Can't figure out local rotation axis.

Hello to all,
Here's my setup: I have a cube which has 6 exterior faces which can be rotated individually along their Y (up) axis. Here are the cubes showcasing their pivot and local axis alt text alt text

The faces are rotated on Y axis with mouse drag with the following code:

 Vector3 _mouseOffset = (Input.mousePosition - _mousePos);
 Vector3 _rotation = Vector3.zero;
 _rotation.y = (_mouseOffset.x + _mouseOffset.y) * rotationSpeedEditor;
                     
 _selectedFace.transform.Rotate(_rotation, Space.Self);
                     
 _mousePos = Input.mousePosition;

Now here's the problem. Upon releasing the mouse, I want to smoothly rotate the face to the closest value between 0, 90, 180, 270 but assigning the localRotation I don't get the desired effect because one face is rotating on the local Y axis and the other on the local X axis. Shouldn't both of them be using the local Y for rotation?

Here's the code I use upon releasing the mouse button

        Vector3 currentRotation =_selectedFace.transform.localRotation.eulerAngles;
         float currentRotationY = currentRotation.y;
         if(currentRotationY <= 45)
         {
             currentRotation.y = 0;
         }
         else if (currentRotationY <= 135)
         {
             currentRotation.y = 90;
         }else if (currentRotationY <= 225)
         {
             currentRotation.y = 180;
         }else if (currentRotationY <= 315)
         {
             currentRotation.y = 270;
         }
         else
         {
             currentRotation.y = 0;
         }
       
         _selectedFace.transform.DOLocalRotate(currentRotation, .2f);

I know I am missing something here but cannot figure out what. Any help is highly appreciated.

EDIT: Just for clarification, I am wondering why rotating the face on the local Y axis, Unity reports it as rotating on the X axis. Added image to showcase the issue: Local Rotation With Log

face2.jpg (84.1 kB)
face1.jpg (83.6 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JonPQ · Apr 20, 2020 at 11:35 PM

try using Transform.RotateAround(). you can specify which axis to rotate around... specify the world Y axis (the "Normal" vector) for each respective surface. https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

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 hdtvee · Apr 21, 2020 at 10:58 AM 0
Share

Does not answer my question. Added clarification.

avatar image JonPQ hdtvee · Apr 21, 2020 at 07:36 PM 0
Share

Still not sure what your problem is.... is it (A) the face rotates on incorrect axis and swings open like a door? or (b) it still visually rotates on the correct axis, but not to where you drag it. or (c) it still visually rotates on the correct axis, but unity reports in the inspector window a different axis rotated than expected that rotated ? Do you have a screenshot of broken result ?

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

235 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 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 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 avatar image

Related Questions

How to clamp character rotation on Y and X axis? 1 Answer

Combining 2 Rotations: Global and Local 2 Answers

Instantiating an object in front of the player 3 Answers

Unity Simulate Local Rotation 0 Answers

Limiting X-Axis rotation to 90 degrees and -90 degrees 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