Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random rotation of multiples of 90°, every second

  • Random rotation of multiples of 90°, every second

    Posted by Simon Francois on November 11, 2015 at 10:05 pm

    Hi all,
    I’m learning expression slowly and recently learned using basically seedRandom and ease expression, which I though of applying here, but for some reason, I’m not getting to what I’m aiming.

    So, my set up is as follows:
    I have 4 items that I want to rotate every second of a -360°, -270°, -180°- -90°, 0, 90°, 180°, 270° or 360° spin.

    The script I originally used was to make the 4 last spins, but even there, I’m not getting something proper. Every second it should spin of a multiple of 90°, and take half of a second to get there. Here is my script:

    segDur = 1;

    seed = Math.floor(time/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = random(0-4)*90;
    seedRandom(seed+1,true);
    endVal = random(0-4)*90;
    ease(time,segStart,segStart + (segDur/2), startVal, endVal);

    It does spin but of various amount of degrees between 0 and 360° whereas I would like to restrict it to only multiples of 90°.

    Can anyone tell me where I have wrong?

    Thanks a lot in advance

    Simon Francois replied 10 years, 8 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 11, 2015 at 10:32 pm

    Try it this way:

    segDur = 1;
    seed = Math.floor(time/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = Math.floor(random(4))*90;
    seedRandom(seed+1,true);
    endVal = Math.floor(random(4))*90;
    ease(time,segStart,segStart + (segDur/2), startVal, endVal);

    Dan

  • Simon Francois

    November 11, 2015 at 11:26 pm

    Thanks Dan, it’s perfect, as usual!

    What was wrong in my script? Was it missing the Math.floor?

  • Dan Ebberts

    November 11, 2015 at 11:30 pm

    Yes, and I wasn’t quite sure what you were doing with the (0-4) in your random calls.

    Dan

  • Simon Francois

    November 11, 2015 at 11:34 pm

    Ha that’s right, I always mistake (0-4) for (O, 4).

    Thanks a lot! Greetings,
    Simon

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy