Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Clamp position in a circle instead of x- and y-axis.

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

    Posted by Saara Salminen on September 4, 2018 at 1:57 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=30737&univpostid=30737&pview=t 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

    Dan Ebberts replied 7 years, 8 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    September 4, 2018 at 3:35 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

  • Saara Salminen

    September 4, 2018 at 4:33 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

  • Dan Ebberts

    September 4, 2018 at 4:42 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

  • Saara Salminen

    September 4, 2018 at 4:48 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

  • Dan Ebberts

    September 4, 2018 at 5:13 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

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