Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Calculating Change In Position(Delta) Using Motion Tracking Data

  • Calculating Change In Position(Delta) Using Motion Tracking Data

    Posted by Alex Macnair on January 6, 2013 at 4:22 am

    Hi there, I am fairly new to using expressions in After Effects and I am in need of some guidance. I am working on a project where I am using the X,Y position of a Null Object (Generated via a motion track) to calculate the velocity of the tracked object.

    This the expression I am using to pull the X,Y position and find it’s change in location every frame:
    ((effect("X")("Slider")-effect("X")("Slider").valueAtTime(time-(1/3)))^2)+((effect("X")("Slider")-effect("X")("Slider").valueAtTime(time-(1/3)))^2)
    I am storing the X,Y position as two slider values, as you can see from the expression.

    My problem is that even though the X and Y values are changing as they should be, the expression output is remaining at 4.00 and for a specific frame it will jump up to 6.00 and then go back to 4.00. I am baffled as to why, I assume that I am doing something wrong with using the valueAtTime…

    Here is a screenshot of all of my sliders and their values: https://i.imgur.com/soLIO.png
    And here are all of my expressions: https://i.imgur.com/bUPTv.png

    Thank you in advance for your help!

    View post on imgur.com

    Alex Macnair replied 13 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Darby Edelen

    January 6, 2013 at 6:46 am

    Well, one thing that jumps out at me is that you’re using the ^ operator, which doesn’t do what you want it to. The ^ is a bitwise XOR operation:

    https://en.wikipedia.org/wiki/Bitwise_operation#XOR

    What you want to do is probably closer to:

    x = effect(“X”)(“Slider”) – effect(“X”)(“Slider”).valueAtTime(time – framesToTime(1));
    Math.pow(x, 2);

    Also I’m not sure that all of your expressions are necessary for your stated goal. If you want the rate of change of the null’s position have you tried:

    thisComp.layer(“End of Shot”).transform.position.speed;

    The result is in pixels/second. No need to get Pythagoras involved 🙂

    Darby Edelen

  • Alex Macnair

    January 6, 2013 at 7:02 am

    Thank you so much, the XOR operation explains the strange results.

    [Darby Edelen] “Also I’m not sure that all of your expressions are necessary for your stated goal. If you want the rate of change of the null’s position have you tried:

    thisComp.layer(“End of Shot”).transform.position.speed;

    The result is in pixels/second…”

    No I did not know about this but I will defiantly use it instead! 🙂

    Thanks again for the help, I really appreciate it!

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