Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Looping Random Orientation Expression

New Here ,
Sep 12, 2019 Sep 12, 2019

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

TOPICS
Expressions , How to
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Sep 19, 2019 Sep 19, 2019

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

...
Translate
Engaged ,
Sep 19, 2019 Sep 19, 2019
LATEST

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines