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 /
  • Help Room /
avatar image
1
Question by evrov · Nov 09, 2016 at 12:53 PM · cubesmoothrotationsdegrees

Smooth cube rotation exactly 90 degrees

Hello, I am new to Unity3D and want to improve myself. I try to rotate a cube smoothly on 90 degrees around its own axis if button is clicked. It is easy on the first look, but rotating the cube its local axis are changed in the global space, so when I try to rotate it around Y axis (Vector2.up) I expect it will be rotated in all cases around the global Y axis that is not changed, because the local Y is on another place in the space.alt text

You can see better on the picture what I mean. Here the cube Y axis is more like X axis, but again I want to rotate around default Y axis that in this case is Z axis. After many rotations I do not know where is my Y, X or Z axes. Can you help me ?

Thanks

unitycube.png (30.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by doublemax · Nov 09, 2016 at 01:13 PM

 transform.RotateAround(transform.position, Vector3.up, 20 * Time.deltaTime);
Comment
Add comment · Show 4 · 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 evrov · Nov 09, 2016 at 01:35 PM 0
Share

Yes, but I want also clicking on the cube smooth rotation on exactly 90 degrees.

avatar image doublemax evrov · Nov 09, 2016 at 02:38 PM 1
Share
 using System.Collections;
 using UnityEngine;
 
 public class RotateTest : $$anonymous$$onoBehaviour
 {
   void Update ()
   {
     if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) )
     {
       StartCoroutine( RotateAround( Vector3.up, 90.0f, 1.0f) );
     }
   }
 
   IEnumerator RotateAround( Vector3 axis, float angle, float duration )
   {
     float elapsed = 0.0f;
     float rotated = 0.0f;
     while( elapsed < duration )
     {
       float step = angle / duration * Time.deltaTime;
       transform.RotateAround(transform.position, axis, step );
       elapsed += Time.deltaTime;
       rotated += step;
       yield return null;
     }
     transform.RotateAround(transform.position, axis, angle - rotated );
   }
 }


You should also check the LeanTween or iTween assets which are both free and turn tasks like this into a one-liner.

avatar image evrov doublemax · Nov 09, 2016 at 02:54 PM 0
Share

Thanks doublemax! It works, but rotating the cube it changes also its angle in the space. I need when the cube is rotated in the space and XYZ axes are in totally different place from its original, again to rotate on the vertical axis, that can be Z or X or Y. Also i will check the ITween and LeanTween, thank you about this information

Show more comments
avatar image
0

Answer by evrov · Nov 09, 2016 at 02:58 PM

On the attached picture my Y axis is more like x axis in the global space. So I want to rotate vertical again and in this case around Z axis, because it is the vertical in the current situation.

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

79 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

Related Questions

How do I limit rotations for both positive and negative degrees? 1 Answer

How do I smooth motion over a cube connection? 0 Answers

How to smoothly change position 1 Answer

Why isn't my object lerping ? C# 2 Answers

models problem always "stepped" 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