Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Moving Null into a circle (clamp expression)

  • Moving Null into a circle (clamp expression)

    Posted by Cyril Drouin on September 24, 2015 at 6:44 pm

    Hi everybody,

    I’m using Clamp expression for stop my controller (Null), it’s useful for a character rig.
    But it’s always moving my null into a square or rectangle.
    Is there a way to moving my null into a circle?

    I think i have to use the cos and sin but i don’t know how to mix clamp with that.

    Sorry for my bad english and thank you a lot

    x= clamp(value[0],100,200);
    y= clamp(value[1],100,200);
    [x,y]

    Hernan Bernardo Vieites replied 5 years, 5 months ago 3 Members · 2 Replies
  • 2 Replies
  • Kalleheikki Kannisto

    September 24, 2015 at 8:55 pm

    Probably not the neatest code for the purpose, but this does it:

    origin_x=150,
    origin_y=150;
    radius = 50;
    x0=value[0]-origin_x;
    y0=value[1]-origin_y;
    distance0 = Math.sqrt(x0*x0+y0*y0);
    distance = Math.min(distance0,radius);
    if (distance0>radius){
    distance_mult = distance/distance0;
    }else{
    distance_mult = 1
    }

    x=origin_x+distance_mult*x0;
    y=origin_y+distance_mult*y0;

    [x,y]

    set origin_x and origin_y to the center point of the circle and radius to the radius of the constraint area.

  • Hernan Bernardo Vieites

    March 30, 2021 at 7:29 pm

    Hello Kalleheikki Kannisto! I know this post is 6 years old but I found your expression thanks to Google and it works for me. The only problem is that I have to set the values to origin_x and origin_y of a null PARENTED to another layer.

    So the expression I am looking for would be something like:

    origin_x=GLOBAL VALUES OF THE CENTRAL NULL.

    I don’t know if I should use toWorld or toComp or where I should place them to get your expression to work. I hope you read this and can help me.?

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