Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 shadow11235 · May 17, 2013 at 10:32 PM · rotatelerpanglerolldice

How to rotate a dice to a final angle ?

Hello all, I have a die that is rotating around all 3 axis , and I am trying to get it to rotate to its final rotation (result I want )? But if f the die is rotating on the x-axis in any direction, it has to keep rotating the same way until it hits the final desired angle, without having to rotate in the opposite direction ? Is lerp what I need to use ?

Those are the final rotations I have :

 DieRotations[0] = new Vector3(180,0,0);
 DieRotations[1] = new Vector3(90,180,0);
 DieRotations[2] = new Vector3(270,0,0);
 DieRotations[3] = new Vector3(90,0,0);
 DieRotations[4] = new Vector3(0,0,90);
 DieRotations[5] = new Vector3(0,0,0);

So Let's say the dice is rotating along all 3 axis clockwise, and once I call my function if the current angle is let's say is Angle(190,200,5) and the desired angle is let's say DieRotaction[0] it has to keep rotating in the same direction until it hits the desired rotation. Not sure if I was clear or if I made too confusing...I appreciate any help!

Thanks!

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 Vonni · May 18, 2013 at 12:36 AM

Could you maybe record 6 die throws with all 6 results and use those?

if not:

EDIT 2: Was bored, made more clear

 // This script is on the dice
  
 var DieRotations array here...
 var wantedRotation : Vector3;

 function Update () {
 
    // Some code to make die spin on all axis for random amount of time here.
    
    // Some code to randomly call a function after some random time
    wantedRotation = StopDieOnDecidedNumber(2);

    // Start some coroutine here with some Slerp function
 
 }
 
 function StopDieOnDecidedNumber ( number : int ) : Vector3 {
 
    var currentRotation : Vector3 = transform.localEulerAngles;
    var wantedRotation : Vector3;
    var x_fullSpins : int = Mathf.Floor(currentRotation.x/360);
    // etc y
    // etc z
 
    currentRotation.x -= x_fullSpins*360;
    // etc y
    // etc z

    if(currentRotation.x > DieRotations[number].x){
         wantedRotation.x = (x_fullSpins+1)*360 + DieRotations[number].x;
    }
    else{
         wantedRotation.x = (x_fullSpins)*360 + DieRotations[number].x;
    }
    if(etc y...)else
    if(etc z...)else

    return wantedRotation;
 
 }
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 shadow11235 · May 20, 2013 at 08:44 PM 0
Share

Thanks a lot Vonni!

I am wondering after calculating the wantedRotation, a slerp would not work in order to rotate the die as I don't have a RotateTo now, I only have the angle of rotation. I have tried using the code below to rotate the dice bit it keeps rotating and I can notice it changing direction of rotation almost :

 if (!stoppedX || !stoppedY || !stoppedZ)
         {
             if (localRotation.x - DieRotations[DieResult-1].x > 3.6f ||localRotation.x - DieRotations[DieResult-1].x < -3.6f )
                 gameObject.transform.Rotate(rotationToResult.x*speed,0.0f,0.0f,Space.Self);
             else
                 stoppedX = true;
             
             if (localRotation.x - DieRotations[DieResult-1].y > 3.6f ||localRotation.y - DieRotations[DieResult-1].y < -3.6f)
                 gameObject.transform.Rotate(0.0f,rotationToResult.y*speed,0.0f,Space.Self);
             else
                 stoppedY = true;
             
             if (localRotation.x - DieRotations[DieResult-1].z > 3.6f ||localRotation.z - DieRotations[DieResult-1].z < -3.6f )
                 gameObject.transform.Rotate(0.0f,0.0f,rotationToResult.z*speed,Space.Self);
             else
                 stoppedZ = true;
                     
             
         }
         else
             stopped = true;
     
     

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

14 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

Related Questions

How to rotate an object around its 3 axis and translate it on 2 world axis so it looks like its a dice rolling? 3 Answers

How to rotate a character facing direction of movement like sonic the hedgehog 2 Answers

Set Rotation Angle 1 Answer

Making a ball roll and keeping the axis? 2 Answers

How to lock camera angle on key press? 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