ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Clamp position in a circle instead of x- and y-axis.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Saara Salminen
Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 1:57:13 pm

Hi!
I have a comp where one shape layer is called "Leader", and another "Follow". The comp dimensions are 2000, 2000 px, and the shape layers are both positioned in the middle (1000,1000). I wish to create an expression, where the Follow layer always moves in the opposite direction of the Leader layer (on both x- and y-axis), but I also need the position value of the Follow layer to be restricted to a circle with a radius of 500px.

I found a post on this forum about clamping the position into a circle: https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=3073... which works just fine on my Follow layer, but I don't know how to edit the expression so that the layer would also move in the opposite direction of the Leader layer.

Any ideas of how to create an expression that executes both tasks?
Gratefully,
Saara


Return to posts index

Dan Ebberts
Re: Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 3:35:50 pm

This might get you started. You won't see anything happen until you animate the Leader:


p = thisComp.layer("Leader").transform.position;
offset = p.value - p.valueAtTime(0);
val = value - offset;

center = [thisComp.width/2,thisComp.height/2];
radius = 200;
v = val - center;
if (length(v) > radius){
center + normalize(v)*200;
}else{
val;
}


Dan



Return to posts index

Saara Salminen
Re: Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 4:33:28 pm

Hi Dan! That works really well. However, the project I'm working on is a rig, so I would prefer if it would work when moving the Leader around, instead of only when animated. Is that possible?

Many thanks,
Saara


Return to posts index


Dan Ebberts
Re: Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 4:42:06 pm

The expression has to have a reference point to compare to the leader's current position. The reference point can either be where the leader was at a specific time (0 in my example), or a specific point, such as the center of the comp, which, I'm guessing, is probably not what you're looking for either.


Dan



Return to posts index

Saara Salminen
Re: Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 4:48:41 pm

Hi!
The center point actually works perfectly in this case, since the starting point of the shape layers is in the middle of the comp. This helped me a lot, thank you Dan!

Saara


Return to posts index

Dan Ebberts
Re: Clamp position in a circle instead of x- and y-axis.
on Sep 4, 2018 at 5:13:56 pm

It sounds like you figured it out, but for completeness, here's how I'd do that:


p = thisComp.layer("Leader").transform.position;
center = [thisComp.width/2,thisComp.height/2];
offset = p.value - center;
val = value - offset;

radius = 200;
v = val - center;
if (length(v) > radius){
center + normalize(v)*200;
}else{
val;
}



Dan



Return to posts index

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