• 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 UKDv12 · Jan 07, 2015 at 02:53 PM · rotateangleitween

Rotating a Cube slowly to fixed angles

I have a cube and I'm trying to rotate it to specific 90 degree angles.

The camera is facing the cube so that only one side is seen, and the arrow keys are intended to rotate the cube exactly 90 degrees in any direction to see the other sides of the cube. While I can get it to rotate easily, the problem lies in trying to slow down the rotation so that the user can perceive it.

I tried using iTween, and it seemed to work but the rotations were often not to exact degrees (89.901, 269.88, etc.), and soon enough more than one side was perceptible to the user. I read that gravity effects could influence it, but my object has no rigidbody component.

Any help would be greatly appreciated

Current Code

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : MonoBehaviour {
 
     public GameObject objectToRotate;
 
     // Update is called once per frame
     void Update () {
 
         if (Input.GetKeyDown (KeyCode.UpArrow)) {
 
             iTween.RotateAdd(objectToRotate, iTween.Hash("x", 90, "loopType", "none", "space", Space.World)); 
             
         }
         if (Input.GetKeyDown (KeyCode.DownArrow)) {
             iTween.RotateAdd(objectToRotate, iTween.Hash("x", -90, "loopType", "none", "space", Space.World));
 
         }
             
         if (Input.GetKeyDown(KeyCode.LeftArrow)) {
             iTween.RotateAdd(objectToRotate, iTween.Hash("y", 90, "loopType", "none", "space", Space.World));
             
         }
 
         if (Input.GetKeyDown (KeyCode.RightArrow)) {
             iTween.RotateAdd(objectToRotate, iTween.Hash("y", -90, "loopType", "none", "space", Space.World));
             
         }
     }
 
 
 }





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 Owen-Reynolds · Jan 07, 2015 at 04:01 PM

Snap it to the exact coords when done (does iTween tell you when it's done? Is there a callBack? Otherwise time it and wait that longer manually.)

There may be a tiny snap, but it looks good -- like the object locks into place (I might even rotate it 88 degrees on purpose, just to get that effect.)

I don't rotate the way you do (by pushing it,) so this is just a hack: grab rotation.EulerAngles and "round" x, y and z to the nearest -180, -90, 0, 90, 180 or 270. Use ifs if you have to.

Comment
Add comment · Show 3 · 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 UKDv12 · Jan 07, 2015 at 04:44 PM 0
Share

Okay cool. That's kind of where I was heading to next. I like the idea of rotating it by a smaller angle then snapping to place. Thanks for the quick reply!

avatar image UKDv12 · Jan 07, 2015 at 05:11 PM 0
Share

I'm fairly new to unity so pardon my ignorance, but out of curiosity how do you prefer to rotate things?

avatar image Owen-Reynolds · Jan 07, 2015 at 09:05 PM 0
Share

Suppose you want to figure out what picture the user is seeing, and if it's right-side up, and how to make it right-side up if needed. You can "ask the model" by checking forward and up, and that often works.

But, most people with training in program$$anonymous$$g like to split things into the real data rep, and stuff the user sees. In this case, there are only 24 orientations (6 facing, 4 spin.) A lot of work to figure the rules, but when done, you can just say "O$$anonymous$$, I know the rotation for position #14 -- spin to face that way."

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate vector around vector? 2 Answers

Mathf to get point on edge of circle (via radius and angle) 1 Answer

Transform Rotate a certain angle (and back) 2 Answers

Rotate Object to Euler Angle using Physics? 3 Answers

Rotation facing the right way problem 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