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 /
  • Help Room /
avatar image
1
Question by AJNK · Aug 28, 2015 at 03:20 PM · movementcuberotation axis

How to flip cube on its edge?

Hi,

I am working on a 3d demo. In that, I have got plane which is a tiled map. I have cube on that plane. I want to move cube from one tile to another. The movement of cube should be like its getting flipped on its edge.

Same as in this game https://www.assetstore.unity3d.com/en/#!/content/17978

can you guys help me with code? I dont know how to implement it.

Problems that I am facing is, 1. How to know which direction is forward after cube is rolled in any direction? 2. How to roll cube so that it looks like its flipped on edge?

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
3
Best Answer

Answer by AJNK · Aug 28, 2015 at 06:37 PM

I was able to solve this problem by creating empty game object and putting it at the center of the cube and then 4 more empty game on each edge of bottom face.

So my object structure is like --player --centerObject --leftPivot --rightPivot --FrontPivot --RearPivot

Reason for not making centerObject a child of player object is that, whenever player flips its axes changes too and now if centerObject was child of payer object then it will mean that centerObject will also get rotated by it. That is why I have kept it as seperate object and I update its position as player object moves.

then in code of player object

 //whenever original player moves then update centerObject's position
 player.transform.position = gameObject.transform.position;
         GameObject child;
         if (Input.GetKeyDown(KeyCode.UpArrow)){
             child = GameObject.Find("FrontPivot");
             gameObject.transform.RotateAround(child.transform.position, Vector3.left, -90);
         }
         if (Input.GetKeyDown(KeyCode.DownArrow)){
             child = GameObject.Find("RearPivot");
             gameObject.transform.RotateAround(child.transform.position, Vector3.left, 90);
         }
         if (Input.GetKeyDown(KeyCode.LeftArrow)){
             child = GameObject.Find("LeftPivot");
             gameObject.transform.RotateAround(child.transform.position, Vector3.forward, 90);
         }
         if (Input.GetKeyDown(KeyCode.RightArrow)){
             child = GameObject.Find("RightPivot");
             gameObject.transform.RotateAround(child.transform.position, Vector3.forward, -90);
         }
Comment
Add comment · Show 1 · 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 jaydeepkasture · Jan 07, 2019 at 10:23 AM 0
Share

Sir How to do the same thing on vertical wall

avatar image
0

Answer by thomasfriday · Jul 10, 2021 at 03:34 PM

Here's a short Youtube video that covers exactly how to roll a cube on its edges: https://youtu.be/06rs3U2bpy8


rolling cube

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

28 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

Related Questions

How do I rotate my object back to the world's up direction whilst keeping it's forward direction? 0 Answers

Rotate Object Axis On Swipe Cam Rotation - Android 1 Answer

Player Rotation Around Mouse 0 Answers

How can I make my GameObject rotate this way? 0 Answers

Player Rotation and movement 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