Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Am I doing this right?

  • Am I doing this right?

    Posted by Conrad Olson on November 30, 2006 at 12:52 pm

    I am trying to teach myself how to use expressions (with a lot of help from this forum I should add).

    One thing I’ve needed to do several times in my projects is to work out the direction that something is traveling at any point in time so I can adjust and other property or object accordingly. In the case bellow I have set up a particle emitter to move around the screen and I wanted the angle of the emitter to change so that it looks like the tail of a firework or something. I haven’t come across a straight forward way of doing this so I’ve done the following:

    old_pos=effect(“Particle Playground”)(“Position”).valueAtTime(time-0.2);
    new_pos=effect(“Particle Playground”)(“Position”);
    y_was=old_pos[1];
    x_was=old_pos[0];
    y_is=new_pos[1];
    x_is=new_pos[0];
    y_dif=(y_was-y_is);
    x_dif=(x_was-x_is);
    angle=Math.atan2(y_dif, x_dif);
    deg_angle=radiansToDegrees(angle);
    [deg_angle+90];

    This works well but is it the simplest way of doing this or is there an easier way?

    Thanks

    Conrad

    Conrad Olson replied 19 years, 5 months ago 3 Members · 6 Replies
  • 6 Replies
  • Mylenium

    November 30, 2006 at 1:07 pm

    Looks okay by me ;O). One could probably concatenate a few things into single lines, but the code is clean and understandable. As an alternative instead of calculating the angle yourself, you could use lookAt(new_pos,old_pos), but it’s basically meant for working in 3D psace, so results may sometimes be wrong.

    Mylenium

    [Pour Myl

  • Conrad Olson

    November 30, 2006 at 2:18 pm

    Cool, thanks. I’m glad I’m doing it right.

    I’m a little comfussed about the lookAt command and how it works. I’ve just read about it in the manual but it doesn’t make sense to me. How would I use that instead?

    Cheers

    Conrad

  • Mylenium

    November 30, 2006 at 5:37 pm

    lookAt() generates a set of orientation angles – you give it a source position from which to look, then a target at which to look. The angles are generated as an array, so you would extract any angle using something like this:

    pos_new=position;
    pos_old=position.valueAtTime(time-0.2);

    angles=lookAt(pos_old,pos_new);

    angle=angles[0];

    [angle]

    Mylenium

    [Pour Myl

  • Dan Ebberts

    November 30, 2006 at 7:16 pm

    This should work:

    v = effect(“Particle Playground”)(“Position”).velocity;
    a = radiansToDegrees(Math.atan2(v[1],v[0]));

    Dan

  • Conrad Olson

    December 4, 2006 at 2:44 pm

    I thought there might be a solution using the velocity property but I could find anywhere in the manual that told me what it returns. What values are in the array that it generates? Are v[1] and v[0] the vertical and horizontal speeds of the motion?

    Thanks

    Conrad

  • Conrad Olson

    December 4, 2006 at 3:00 pm

    I’ve just got a version of the porject working with your solution Dan (I’m still only guessing what the array values from the velocity are) but the angle seems to be more jumpy as the particle emmiter moves around. Is that because the velocity property is more accurate than the was I was doing it? I’m guessing the inaccuracy in my method smoothed out the change in motion at sharp corners in the motion path. Would that happen?

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