Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions re: seedRandom(index,true)

  • re: seedRandom(index,true)

    Posted by David Rodriguez on May 14, 2008 at 8:30 pm

    I have used seedRandom(index,true); twice in this expression.
    The first works exactly as I would expect it to.
    The second seedRandom(index,true); applied to elasticity achieves undesirable results.
    This bounce expression is applied to hundreds of ball graphics, instead of randomizing the elasticity across all of the balls it raises the elasticity from .89 to 1 from the left of the screen to the right.

    Screen Shot
    https://img517.imageshack.us/img517/1050/notrandomsp8.jpg

    Vy0 =200; //initial y velocity (pixels/second)
    seedRandom(index,true);
    Vx0 =random(-400,400); // initial x velocity (pixels/second)
    g = 2500; // gravity (pixels/second/second)
    floor = 1050;
    seedRandom(index,true);
    e = random(.89,1); //elasticity

    b = floor – position[1];
    h = b + Vy0*Vy0/(2*g);
    T = Vy0/g + Math.sqrt(2*h/g);

    if (time < T){ y = Vy0*time - g*time*time/2 + b; }else{ Vy = -(Vy0 - g*T); Vy *= e; t = time - T; y = Vy*t - g*t*t/2; } [position[0] + Vx0*time, floor - y] What have I done now? Any help is very much appreciated! David

    David Rodriguez replied 18 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 14, 2008 at 8:40 pm

    When you reset the seed to a previous value (the layer’s index in this case) the random sequence you get when call random() starts over. So in your case,

    random(-400,400);

    and

    random(.89,1);

    actually generate the same random number, scaled by the parameters inside the parens. So that means that elasticity will be proportional to the x velocity, which will give you exactly the results you are seeing.

    What were you trying to accomplish be resetting the seed?

    Dan

  • David Rodriguez

    May 14, 2008 at 9:02 pm

    I would like some of the balls to bounce higher than others.
    I thought that using Random would randomly choose an elasticity between .89 and 1

    -David

  • Dan Ebberts

    May 14, 2008 at 9:13 pm

    It will, but you don’t need (or want) to reset the seed first. You should only need to use seedRandom() once in an expression unless you’re doing something tricky and need to regenerate a random number from the past.

    Dan

  • David Rodriguez

    May 14, 2008 at 9:23 pm

    Brilliant! I actually understand!

    Is this expression easily changed from one bounce to two?
    If not then I can be happy with what you helped me achieve, but two bounces would be nice.

    Con Muchas Gracias,
    David

    -David

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