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!
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;
}