Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions rotation changes vector – driving along

  • rotation changes vector – driving along

    Posted by Christopher R. green on May 14, 2009 at 3:56 am

    Hi.
    This is probably a Flip V, or Dan E question.
    What I’d like to do:
    In 2D (for the sake of simplicity), make an object move in a direction based on its rotation, given that:

    a) the object will never go in a positive y direction (so, always variations, that is, combinations of -y, +x and -x, but never +y);

    b) may stop or change speed, but this will need to be arbitrary (that is, keyframe- or expression-driven/randomized);

    [these remaining points may be obvious, but just to be clear]

    c) the rotation will be arbitrary;

    d) the object must not ‘slide’, it should move perfectly according to its rotation, so it should look like a driven car;

    e) I do not want to animate the position and point the object vector-wise

    Could this be a fun challenge? Or is it obvious and I’m just burned out?

    Thanks in advance for any help.

    -CG

    Christopher R. green replied 16 years, 12 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    May 14, 2009 at 5:00 am

    I think this would be a complicated expression. I gets back to the issue that expressions have no memory. Assuming that the rotation and speed have been changing, the expression has no easy way of knowing what position it calculated on the previous frame. The solution is that at each frame, the expression has to calculate everything that has happend at each previous frame (starting at th4e first frame) and keep a running tally of where it was at each frame. Certainly possible, but not simple.

    Dan

  • Filip Vandueren

    May 14, 2009 at 4:45 pm

    I’m not sure if I understand that “never go negative in Y”, this would only occur if the rotation would be more than +/- 90°, so you have that under control.

    What would happen if the rotation would yield a negative Y, would Y be 0 ?

    I think this does what you need, If I understand correctly:

    position:

    fd=thisComp.frameDuration;
    speedSlider=thisComp.layer("Speed").effect("Speed")("Slider");

    p=position.valueAtTime(0);

    for (t=0;time>t; t+=fd) {
    sp=speedSlider.valueAtTime(t)*fd;
    vector=toCompVec([0,-sp],t);

    if (vector[1]>0) {
    vector=[vector[0],0];
    }
    p+=vector;
    }

    p;

    as you see in Line 2, I reference a Slider called “Speed” on a layer “Speed”.
    You can keyframe or wiggle that slider, and also the rotation of this layer can be keyframed or wiggled

  • Filip Vandueren

    May 14, 2009 at 4:59 pm

    BTW, if we forget the -Y stuff, this is very easily translated into 3D:


    fd=thisComp.frameDuration;
    speedSlider=thisComp.layer("Speed").effect("Speed")("Slider");

    p=position.valueAtTime(0);

    for (t=0;time>t; t+=fd) {
    sp=speedSlider.valueAtTime(t)*fd;
    vector=toWorldVec([0,-sp,0],t);

    if (vector[1]>0) {
    vector-=[0,vector[1],0];
    }

    p+=vector;
    }

    p;

    Thanks to the ToWorldVec(), this takes into account orientation and x-y-z-rotation

  • Christopher R. green

    May 14, 2009 at 7:28 pm

    [Filip Vandueren] “I’m not sure if I understand that “never go negative in Y”, this would only occur if the rotation would be more than +/- 90°, so you have that under control.”

    Never go positive in Y, that is, ‘down’.

    But now I’m going to see what you came up with …

  • Christopher R. green

    May 14, 2009 at 7:51 pm

    Um…
    Perfect?

    That is really cool, Flip.

    Dan, you must’ve over-thought the problem!

    This is going into my “favorite tricks to steal from others” folder!

    I’m giddy.

    DANG!

    nice.

    Thank you.

  • Christopher R. green

    May 14, 2009 at 8:06 pm

    You can pretty much disregard the +y thing. I just put that in in case it made any difference in the way the solution evolved. It is, of course, dependent on how the rotation is done.

    Thanks again!

    cg

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