Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Particle Playground and Expressions Help

  • Particle Playground and Expressions Help

    Posted by Mbs on June 15, 2005 at 5:16 am

    So I’m probably biting off more than I can chew, but I’m trying to learn the Particle Playground and expressions at the same time.

    Ultimately, I’m trying to create an overhead scene with many birds (the particles) randomly flying (crisscrossing) through the frame (picture the original Legend of Zelda meets Hitchcock’s Birds). The problem I’m facing, is how to create expressions that (a) randomly position the Particle Playground’s cannon just outside of the frame (the birds need to fly in from random “elsewheres”) and (b) control the cannon’s direction so it generally fires into the frame (i.e. – if the cannon is off frame right, it should shoot leftish). If this wasn’t enough, I would also ideally like the particles to randomly “die” (disappear).

    My clumsy attempt at part (a) is below. While it seems to work (the cannon remains out of the frame, which is 720 x 534), (a) i know the code is super crude and (b) some of the particles are still “born” within the frame, despite the cannon being off screen.

    If anyone can offer any help, suggest a different approach, or turn me towards a tutorial that might help, it would be great.

    thank you in advance.

    a = random(-20,740);
    b = random(-20,554);
    if ( ( (a < 720) && (a > 0) ) && ( (b < 534) && (b > 0) ) ) {
    while ( ( (a < 720) && (a > 0) ) && ( (b < 534) && (b > 0) ) ) {
    a = random(-20,740);
    b = random(-20,554);
    }
    }
    [a,b]

    Mbs replied 19 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Mylenium

    June 15, 2005 at 6:06 am

    Particle systems are dynamic, you cannot really control when a particle is born. In your case just that might happen while your layers are jumping across the frame. You need to have your path outside the frame all the time and that’s done most easily using keyframes. Try the following:

    a) create a Null object and name it “Cannon Helper”.
    b) Animate its position so it forms a closed path around your window.
    c) Add some code to your cannon position like that

    variation=random(0,10);
    helper=thisComp.layer(“Cannon Helper”);

    new_X=helper.position.valueAtTime(variation)[0];
    new_Y=helper.position.valueAtTime(variation)[1];

    [new_X,new_Y]

    d) Add som code to the direction of the cannon

    helper=thisComp.layer(“Cannon Helper”);
    helper_X=helper.position[0];
    helper_Y=helper.position[1];
    center_X=thisComp.width/2;
    center_Y=thisComp.height/2;
    diff_X=helper_X-center_X;
    diff_Y=helper_Y-center_Y;

    angle=readiansToDegrees(Math.atan2(diff_Y,diff_X));

    [angle]

    Should work perfectly for what you are trtying to do. Just adjust the values as needed.

    Mylenium

    [Pour Myl

  • Roland R. kahlenberg

    June 15, 2005 at 1:27 pm

    [Mylenium] “Particle systems are dynamic, you cannot really control when a particle is born.”

    Using Particle Playground’s Cannon parameter, you can actually emit particles outside of a layer’s boundaries PLUS control the number of particles emitted using the Particles per Second parameter.

    To ensure that emitted particles are directed where they should be, you should be looking at the Cannon’s Direction. As long as the Cannon’s Direction is pointed towards center (or slightly off – depending on your taste – via a random/wiggle Expression method) using a Null Layer you shold be fine.

    I’m a lot short of time get an Expression going but hopefully Dan will drop by and sort things out. It’s not that difficult really. You just need to randomize your Cannon’s position so that it does not intrude into the layer’s boundaries (taking into account of the particle’s pixel size) and to ensure that the direction of the particles are centered, regardless of the Cannon’s position (but targeted towards an object, the Null Layer, centered in the composition).

    Hope all this makes sense.

    Best of Luck
    RoRK

    broadcastGEMs.com – the leader in customizable royalty-free animated backdrops

  • Mbs

    June 17, 2005 at 3:18 am

    Thanks so much for the help! I’m trying it out now… i’ll let you know how it goes.

  • Mbs

    June 17, 2005 at 4:20 pm

    Finally got a chance to try this out. Thanks so much for your help.
    The first part seems to work well (

  • Mbs

    June 17, 2005 at 5:01 pm

    Oops! (errant mouse click)

    Finally got a chance to try this out. Thanks so much for your help. While the first part (the expression for the cannon’s position) is giving me positions outside of the frame, I’m still having the problem of some particles being “born” within the frame.

    My null Layer is animating around the frame (in a square – lower left, upper left, upper right, etc.) over the course of 20 sec, so the code I’m using is:

    variation=random(0,20);
    helper=thisComp.layer(“circler”);
    new_X=helper.position.valueAtTime(variation)[0];
    new_Y=helper.position.valueAtTime(variation)[1];

    [new_X,new_Y]

    (where circler is the name of my null object).

    Any thoughts on why particles are popping up in the frame? Could it be my other settings?

    In addition, the second part (the angle the cannon fires) seems to be acting weird.
    The code suggested:

    helper=thisComp.layer(“Cannon Helper”);
    helper_X=helper.position[0];
    helper_Y=helper.position[1];
    center_X=thisComp.width/2;
    center_Y=thisComp.height/2;
    diff_X=helper_X-center_X;
    diff_Y=helper_Y-center_Y;

    angle=readiansToDegrees(Math.atan2(diff_Y,diff_X));

    First of all, am I correct in thinking that the first line should actually be grabbing the position of the Cannon, and not the Cannon helper? With that difference, i’m still getting erratic angles. I added a Slider Control to debug, and Diff_X and Diff_Y seem to be coming out all right, so I figure the problem is in the last line (apart from the typo in “radians”). Anyone have any ideas? Thanks in advance.

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