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 /
avatar image
0
Question by docchang · Apr 30, 2016 at 11:42 AM · axiscuberolling

Detect the up axis when rolling a cube?

I've successfully roll a cube using the example here: http://unitynoobs.blogspot.com/2011/02/roll-cube.html

How can I determine which axis is going to be in the up position?

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
0

Answer by Pandantly · May 01, 2016 at 07:24 AM

This probably isn't the most efficient (or creative) solution, but here's an idea:

Imagine you've created a rubik's cube in unity, with it's staring position being with the white side up. You can go to the scene and take note of it's current rotation value. Then, turn the cube so the red side is up, and take note of it's current rotation value, continuing until you've finished all sides. Then, in your script, you can create a variable for each different rotation value. For instance:

 /* Variables could be used to store the rotation value the cube had when a certain side    was facing upwards */

 Vector3 blueUp = new Vector3 (0, 0, -90); 

Then, you could simply check each frame which variable the cube's current rotation value matches. If the cube's r-value is equal to blueUp, the blue side is facing upwards. If it's equal to whiteUp, the white side is facing upwards.

One could argue that, in a sense, this is "cheating," but it's an option. Hope this helps!

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

Answer by N1warhead · May 01, 2016 at 03:47 AM

Like predict what axis will be the up position after the dice is rolled?

Unfortunately this won't be easy as it depends how you're even doing this first. Like if you are using pure physics to role the dice, I highly doubt it will be possible to pre-determine the axis of which will be pointing up because every roll at least in real life will never be the same, the bounce, the force, etc. Now I'm sure it is possible if you really spend some time to make a big system that can accurately predict this stuff, however - there will not be any easy solution with a couple lines of code, unless you can figure out the math involved from the force, bounce, drag, rotational force, Angular Drag, etc.

Aside from that the only way i can see it even being possible is if you make a bunch of Animations that plays random animations, which wouldn't really be so great.

prediction isn't easy man, but predetermined stuff is. Now what you CAN DO is use some simple bools that will TELL you which one is angled Upwards.

Something like this.

 private bool x;
 private bool y;
 private bool z;
 
 private Transform tran;
 private Rigidbody diceRigid;
 
 void Start(){
 tran = this.transform;
 diceRigid = GetComponent<Rigidbody>();
 }
 
 void Update(){
 //So we check if the X axis is point up and if the Dice is no longer moving.
 if(tran.eulerAngles.x ==  90 && diceRigid.velocity == Vector3.zero){
 //Do the same for Y and Z as well.
 //Do Code Here, x at 90 degrees = straight up.
 x = true;
 }
 
 }
 
 //So pretty much, if X axis = 90 degrees, then X is true. So therefore X is straight up.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnMouseDown() cube face? 1 Answer

Object Problems with colliders? 1 Answer

Everytime ball goes to new plane it bounces 2 Answers

How can i stop a WASD Cube Player to move into nothing on a plattform? 2 Answers

moving a cube 2 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