Copy link to clipboard
Copied
Hey everyone! I am creating a randomly rotation 3D cube and I want to to have the animation loop but I cannot figure it out.
Right now the expression I have on my orientation is this:
seedRandom(index, true);
start_time = 0;
end_time = 10;
range_start = [-360, -360, -360];
range_end = [360,360,360];
random_end = random(0,1);
start_anim = start_time + inPoint;
end_anim = random_end + end_time + inPoint
start = random(0,0,0);
end = random(range_start,range_end);
ease(time, start_anim, end_anim, start,end);
I have tried changing the end = to 0,0,0 as well so that it would start and stop in the same spot but that just makes any movement go away.
If anyone has any tips for me that would be amazing! Thank you so much!
Best,
Kay
1 Correct answer
Since the last position is a random value between 0 and 360 on all axes, and the beginning is a random value between -360 and 0, it makes sense that they're not looping, because they're unlikely to be the same value (it would only happen if both random functions returned [0, 0, 0]. You need to either rotate a multiple of 360° over the whole animation on each axis (If the cube is the same on all sides you could make it a multiple of 90°), or come back to the start position.
So the second last line
...Copy link to clipboard
Copied
Since the last position is a random value between 0 and 360 on all axes, and the beginning is a random value between -360 and 0, it makes sense that they're not looping, because they're unlikely to be the same value (it would only happen if both random functions returned [0, 0, 0]. You need to either rotate a multiple of 360° over the whole animation on each axis (If the cube is the same on all sides you could make it a multiple of 90°), or come back to the start position.
So the second last line should be
let minRotations = [-1, -1, -1];
let maxRotations = [1, 1, 1];
let offset = random([360, 360, 360]);
// this makes writing the next part easier
// it defines a function r which generates a random number from the parameter and rounds it
let r = function(n){return Math.round(random(n))};
//returns a whole number of rotations for start and finish.
//NB in this case it will be zero rotations for both about ¼ of the time
start = offset + [r(-1), r(-1), r(-1)] * 360; //or *90
end = offset + [r(1), r(1), r(1)] * 360; //ditto

