Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random number from array to target layer

  • Random number from array to target layer

    Posted by David Wiffen on November 22, 2010 at 4:18 pm

    Hi Everyone,

    Ok hopefully this is simple enough. Here’s my expression…

    posx = thisComp.layer(“Emitter.2”).transform.position[0];
    posy = thisComp.layer(“Emitter.2”).transform.position.wiggle(thisComp.layer(“WiggleEmitter”).effect(“Freq”)(“Slider”),thisComp.layer(“WiggleEmitter”).effect(“Amp”)(“Slider”))[1];
    [posx,posy];

    All I want to do is where it references “Emitter.2” I want to have an expression that says randomly select an number from an array of x amount and apply to this reference. So when I duplicate the layer up it will pick a different number each time.

    Eg. Emitter.1 / Emitter.2 / Emitter.3 / Emitter.2/ Emitter.1 / Emitter.3 and so on…

    Hope that makes sense!

    David Wiffen replied 15 years, 5 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    November 22, 2010 at 4:59 pm

    This would be one way to randomize references to the 3 layers:

    seedRandom(index,true);
    n = Math.floor(random(3)) + 1;
    emitterName = “Emitter.” + n;
    posx = thisComp.layer(emitterName).transform.position[0];

    Dan

  • David Wiffen

    November 22, 2010 at 5:15 pm

    Very impressive – Thanks Dan!

    One more question…If I have other expressions on the same layer that I want to have the same value as what the random expression chooses…how would I do that?

    eg.

    This is on position x and y and works great:

    seedRandom(index,true);
    n = Math.floor(random(3)) + 1;
    emitterName = “Emitter0” + n;
    posx = thisComp.layer(emitterName).transform.position[0];
    posy = thisComp.layer(emitterName).transform.position.wiggle(thisComp.layer(“WiggleEmitter”).effect(“Freq”)(“Slider”),thisComp.layer(“WiggleEmitter”).effect(“Amp”)(“Slider”))[1];
    [posx, posy] – value + wiggle(thisComp.layer(“WiggleEmitter”).effect(“Freq”)(“Slider”),thisComp.layer(“WiggleEmitter”).effect(“Amp”)(“Slider”));

    This is on the z and needs to have the same random value as the x and y have for the emitter number:

    seedRandom(index,true);
    n = Math.floor(random(3)) + 1;
    emitterName = “Emitter0” + n;
    thisComp.layer(emitterName).transform.position[2];

    thanks again Dan – you’re talented guy!

  • Dan Ebberts

    November 22, 2010 at 8:07 pm

    You’d have to put the random calculation on a slider control and have both expressions pick it up from there. The expression on the slider would just be:

    seedRandom(index,true);
    Math.floor(random(3)) + 1;

    Dan

  • Lloyd Alvarez

    November 22, 2010 at 9:28 pm

    You could add a slider control and generate the random number there then have X and Z get the number from there.

    This is the code you should put on the slider control:
    seedRandom(index,true);
    Math.floor(random(3)) + 1;

    And this would be the updated code for Z:

    n=effect("Slider Control")("Slider").value;
    emitterName = "Emitter0" + n;
    thisComp.layer(emitterName).transform.position[2];

    -Lloyd

    https://aescripts.com

  • David Wiffen

    November 23, 2010 at 9:20 am

    Brilliant – thanks Both!
    Really really appreciate it!

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