• 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 bigwade · Dec 20, 2014 at 07:40 PM · rotatecuberelative

Rotate a Cube by 90 degree

Hello,

I have a simple cube, with a camera in front of him. So in the game render we just see a face of the cube. And when i click on the arrows (up,down,left or right) i want the cube rotate by 90 degree in the direction of the arrow to show an other face of the cube.

The probleme is, for example when a first rotate the cube to the left, and i want to rotate it to the up, it will rotate to the up but relative to the first position of the cube. Like this:

alt text

I use DOTween for the rotation (and i have the same result with iTween). And i try locale rotate with a parent and normal rotate without parent. The result is the same. For rotating the cube, i get the x,y and z rotate values like this:

 Vector3 v3 = transform.rotation.eulerAngles;
 xCube = v3.x;
 yCube = v3.y;
 zCube = v3.z;

and when an arrow is clicked:

 void left(){
 transform.DOLocalRotate(new Vector3(xCube, yCube+90, zCube), 1);
 }
 
 void right(){
 transform.DOLocalRotate(new Vector3(xCube, yCube-90, zCube), 1);
 }
 
 void up(){
 transform.DOLocalRotate(new Vector3(xCube+90, yCube, zCube), 1);
 }
 
 void down(){
 transform.DOLocalRotate(new Vector3(xCube-90, yCube, zCube), 1);
 }


I'm new with Unity and 3D. I understand WHY the cube rotate this way, but i don't understand how to do what i want.

Can you help me ?

sans titre-1.jpg (50.1 kB)
Comment
Add comment · Show 9
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 jakovd · Dec 20, 2014 at 07:47 PM 0
Share

what is this DoLocalRotate? use tranform.Rotate ins$$anonymous$$d.

 void Left()
 {
 transform.Rotate(new Vector3(90f, 0f, 0f));
 }

EDIT: ok, I've noticed you are using DOTween. Use DORotate ins$$anonymous$$d DOLocalRotate.

avatar image bigwade · Dec 20, 2014 at 08:25 PM 0
Share

Already tried DORotate, and i get the same resultat.

avatar image jakovd · Dec 20, 2014 at 09:14 PM 0
Share

Check out the documentation for DORotate. There is a third parameter Rotate$$anonymous$$ode for that method.

avatar image bigwade · Dec 20, 2014 at 09:38 PM 0
Share

I tried Rotate$$anonymous$$ode.WorldAxisAdd but it give me weird results. I don't think this is what i'm looking for. There's no way to set the rotation point to 0,0,0 when i rotate my object ? This way, every time i rotate my cube, the values will return to 0. Like i'm always see the 1st face of the cube, but it's another. It would be perfect but i don't know if you can do this... ?

avatar image jakovd · Dec 20, 2014 at 09:49 PM 0
Share

try this way void Left() { transform.DORotate(new Vector3(0,90,0), 1, Rotate$$anonymous$$ode.WorldAxisAdd); }

Show more comments

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.

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 object relative to camera's view 2 Answers

rotate a texture inside a cube 1 Answer

How to scale and move a cuboid so that it fit's between two points? 3 Answers

Apply torque/force to rotate an object around a fixed point 1 Answer

Tracking the rotation of a cube 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