Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Aaron Martinez on July 12, 2008 at 1:13 pm

    hello, i am trying to get a grip on expressions and i have a couple questions…

    i have a little wheel that is traveling from the top left of the screen to the bottom left doing a little zig zag…the animation is in 2D space and the wheel does not travel on a path, the position is key framed 4 times…

    i would llike the wheel to rotate according to the actual distance traveled…

    i have velocity… posotion.speed

    my problems are:
    i do not know how to find the distance…

    i though velocity/time.

    adding up the velocity dividing that by frames and that by seconds…but i feel i am horribly wrong…i am sure there is an easier way…right?

    second question…
    is it possible to accumulate numbers…that is to say counting the value from eachframe and add them together?

    thanks for the help…

    Dan Ebberts
    replied 17 years, 9 months ago
    2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    July 12, 2008 at 5:27 pm

    Sounds like you’re on the right track. Expression results don’t persist from frame to frame. If you want to know what’s happened in the past, your expression generally has to loop through its calculations from frame 0 to the current frame. You can avoid this if you can somehow express your calculation as a function of time, but that’s not always possible.

    In your case, you could write a loop that would accumulate the distance traveled from one frame to the next using something like this:

    accum += length(position.valueAtTime(t), position.valueAtTime(t – thisComp.frameDuration);

    Tricky, but not impossible.

    Dan

  • Aaron Martinez

    July 14, 2008 at 9:06 pm

    Hello Dan,

    thanks for the tip. unfortunately i still havnt gotten very far. i have pasted the expression you gave to me…

    accum += length(position.valueAtTime(t), position.valueAtTime(t – thisComp.frameDuration);

    into position and i received an error. i also pasted it into a text layer to test her out and i got an error. i took the position word from the expression, highlighted it and pickwipped the position of my layer and i still get an error. so my question is where do i paste this line in to get a proper result? thanks for the help…

  • Dan Ebberts

    July 14, 2008 at 9:19 pm

    Ah, OK. That was only meant to be part of the looping expression. Here’s a more complete version to calculate rotation based on distance traveled. It assumes that the diameter is the same as the layer’s width:

    accum = 0;
    for (t = 0; t <= time; t += thisComp.frameDuration){ accum += length(position.valueAtTime(t), position.valueAtTime(t - thisComp.frameDuration)); } 360*accum/(Math.PI*width) Dan

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