Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions How to have multiple points follow separate paths while maintaining the same relative x position

  • How to have multiple points follow separate paths while maintaining the same relative x position

  • Luke Shaw

    May 22, 2020 at 7:34 pm

    I want to mimic a graph similar to this in AE ( https://mf.freddiemac.com/aimi/)
    What i mean by this is, I want to create a mouse cursor and be able to keyframe its position around in my comp and have those 4 points along the line follow the mouses x position but maintain the relative y position to where they are on their path. I have tried everything i can think of, but even when i almost got it working through code there is an offset in speed between each point. Essentially I could drag an object and all of the points would move alone with it, while following their path, but they would all move in the x axis at slightly different speeds offsetting each other

    Essentially I want

    Path 1
    Path 2
    Path 3
    Path 4

    Object 1
    Object 2
    Object 3
    Object 4

    Mouse Cursor

    Object 1
    x position of object 1 is equal to x position of cursor
    y position of object 1 is equal to the y position of path 1 relative to the x position of mouse cursor

    Object 2
    etc..

    Thank you so much to anyone who can help me figure this out

  • Dan Ebberts

    May 22, 2020 at 7:59 pm

    What do these paths look like (your link doesn’t seem to work)?

    Dan

  • Luke Shaw

    May 22, 2020 at 8:29 pm

    Terribly sorry about that. I attached an image to this reply and ill put the link in again to see if it works

    https://mf.freddiemac.com/aimi/

  • Luke Shaw

    May 22, 2020 at 8:30 pm

  • Dan Ebberts

    May 22, 2020 at 10:10 pm

    It’s tricky, but if your graphs are true functions of x (no instances of multiple y values for the same x) you can probably do it with an iterative solution like this simple binary search:


    iterations = 12;
    L = thisComp.layer("Path 1");
    p = L.content("Shape 1").content("Path 1").path;
    xc = thisComp.layer("Cursor").transform.position[0];
    p0 = L.toComp(p.pointOnPath(0));
    p1 = L.toComp(p.pointOnPath(1));
    if (xc < p0[0]){
    p0;
    }else if (xc > p1[0]){
    p1;
    }else{
    lower = 0;
    mid = .5;
    upper = 1.0;
    for ( i = 0; i < iterations; i++){
    pCur = L.toComp(p.pointOnPath(mid));
    if (pCur[0] == xc) break;
    if (pCur[0] > xc){
    upper = mid;
    }else{
    lower = mid
    }
    mid = (upper+lower)/2;
    }
    [xc,pCur[1]]
    }

    Bumping the iterations value should make it more accurate at the expense of rendering performance.

    Dan

  • Luke Shaw

    May 22, 2020 at 10:30 pm

    wow, thank you so much! I’ll try this out over the weekend and let you know how it goes!!

  • Luke Shaw

    May 24, 2020 at 1:49 pm

    Just wanted to followup and say this works exactly how I wanted it to. I cant tell you how much I appreciate your help with this, thank you again and enjoy the rest of your weekend!

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