ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Luke Shaw
How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 7:34:14 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


Return to posts index

Dan Ebberts
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 7:59:17 pm

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

Dan



Return to posts index

Luke Shaw
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 8:29:09 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/


Return to posts index


Luke Shaw
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 8:30:05 pm



Return to posts index

Dan Ebberts
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 10:10:12 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



Return to posts index

Luke Shaw
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 22, 2020 at 10:30:22 pm

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


Return to posts index


Luke Shaw
Re: How to have multiple points follow separate paths while maintaining the same relative x position
on May 24, 2020 at 1:49:36 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!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]