Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Time remap based on velocity/direction?

  • Time remap based on velocity/direction?

  • Mike Douglas

    January 6, 2020 at 9:59 pm

    Hi there, I’m working on a whiteboard explainer video. I have a AE precomp with several hand photos holding a marker, and I’d like it to swap between frames depending on which direction it’s travelling. I have photos for a neutral position, plus up, down, left and right (fairly subtle shifts in the hand so that it looks pretty natural). So, if it’s travelling left, it’d go to frame 1, etc. Ideally it it’s moving too slow, it would just go to the neutral pose, but that’s not really necessary. Not sure if any of this is possible or not?

    I assume it would need to evaluate which direction the precomp is travelling fastest in, as it will likely never be moving JUST vertically or horizontally. So, if it’s going faster in negative X than negative or positive Y, it’d go to frame 1 (left pose).

    Hopefully that makes sense. Thanks so much!

  • Andrei Popa

    January 6, 2020 at 11:24 pm

    Order of poses inside the comp : neutral, up, down, left, right.
    Each holds one frame only.
    Precomp framerate must equal active composition framerate.


    neutralSpeed = 50; //pixels pe second, you can modify this
    vel = position.velocityAtTime(time);

    if (Math.abs(vel[0]) < neutralSpeed && Math.abs(vel[1])< neutralSpeed){
    pose = 0;
    }else if (Math.abs(vel[0])>Math.abs(vel[1])){
    pose = (vel[0]>0) ? 4 : 3;
    }else{
    pose = (vel[1]>0) ? 2 : 1;
    }

    framesToTime(pose)

    Andrei
    My Envato portfolio.

  • Mike Douglas

    January 7, 2020 at 12:10 am

    Wow – that’s perfect! Thanks so very much, Andrei – you’ve just saved me hours and hours of work. Very much appreciated!!

  • Sam Smith

    June 2, 2020 at 3:32 pm

    Andrei,

    Appreciate I’m dragging this one back from a while ago but I’m trying to do something similar and hitting a brick wall.

    The problem is my object is moving on an isometric plane rather than straight up and down so there’s never a point where either axis is 0. Using the expression above it just jumps between two sprites (positive and negative)

    I’ve gotten as far as splitting the two dimensions out using the vel[0] and vel[1] but after that, I’m stumped.

    Any pointers in the right direction would be gratefully appreciated.

    Thanks,

    Sam

  • Sam Smith

    June 2, 2020 at 7:39 pm

    Okay, Just in case anyone else is looking for this I think I’ve solved it using by adapting another piece of time-remap sprite code found on here by Charlie Laud.

    No all I need to do is work out how to keep it in the state it was before if speed = 0.

    directionNum = 0;
    dX = transform.xPosition.valueAtTime(time) - transform.xPosition.valueAtTime(time - framesToTime(1));
    dY = transform.yPosition.valueAtTime(time) - transform.yPosition.valueAtTime(time - framesToTime(1));

    if (dX > 0 && dY > 0) {directionNum = 0;}
    if (dX &lt; 0 && dY &lt; 0) {directionNum = 1;}
    if (dX &lt; 0 && dY > 0) {directionNum = 2;}
    if (dX > 0 && dY &lt; 0) {directionNum = 3;}

    framesToTime(directionNum)

  • Andrei Popa

    June 3, 2020 at 7:01 am

    I dont understand why it jumped only in 2 sprites in your case. It is build for 5 cases. UP DOWN LEFT RIGHT NEUTRAL. On each frame, it shows the one that is bigger(if the object goes left with 45-something degrees difference to horizontal, it shows left. If it goes with 45+something it shows up )
    My expression is very similar to your. I just used the .velocityAtTime() to get the direction instead of accessing valueAtTime(time-frame)
    The 50 pixels per second is for the case in which the speed is very low, case in which it will show the neutral pose.

    Now for the problem with your case. You must go back in time frame by frame until you find a value that is not zero(for the speed) and make the current value that value. This will create long render times if your object sits in place a lot.

    Andrei
    My Envato portfolio.

  • Sam Smith

    June 3, 2020 at 7:59 am

    Not sure either – when I mapped the vel output to a text string it seemed to be that I got one sprite for a positive number and another for the negative. It didn’t seem to know if it was a negative x or y.

    I don’t need a neutral state as the natural pose would be based on what sprite has just been displayed.

    I’m guessing that could be achieved with some kind of

    “if vel=0, then find vel-1 speed and use that”

    With the resting state, I think I’m just going to slow the vehicle sprite down so it appears to be stopped. The scene is zoomed out a fair way so it should be okay, and reduce the number of calculations as I have a lot of small car sprites going around the city.

    Thanks again for your help.

    Sam

Viewing 1 - 7 of 7 posts

Log in to reply.

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