Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects A difficult expression problem (impossible?)

  • A difficult expression problem (impossible?)

    Posted by Erin Shelby on October 30, 2005 at 6:01 am

    I’m really not clear on if this one is possible or not…

    I have a big rectangle and I have a small square, what I’d like to do is make simplified controls so I can move the small square around the parameter of the large rectangle – like a ant that crawls along it’s surface. Ideally, something like a slider expression that I can just slide back and forth and it will move along the path of the rectangles 4-sides.

    The tricky thing I want to do though, is that I’d like to be able to rotate/move the rectangle as well – and the ant/square should stay on the surface of the rectangle.

    possible?

    -grey.

    Erin Shelby replied 20 years, 6 months ago 4 Members · 4 Replies
  • 4 Replies
  • Spritemaster

    October 30, 2005 at 8:28 am

    Of course it’s possible. Here’s a sketchy account, if you need more details let me know. Just a word of warning, I’m writing this off the top of my head without actually trying it out, so I will probably make some silly mistakes you’ll need to correct 🙂

    Let’s say the center of your rectangle is at (xc, yc). Since you want to move the rectangle, just make those parameters controllable by sliders. Also, suppose the rectangle has width w and height h (if you wish, you could even make controls for these, so you can stretch and resize). You have a slider controlling an angle we’ll call th, and finally a slider for the “time” t; as you move t from 0 to 1 your bug will crawl along the perimeter of the rectangle. The 0-1 range is just for convenience, of course; you can choose whatever you like.

    Define variables x0, y0 and set them as follows:

    if t<=0.25 then x0 = xc-w/2, y0 = yc+h/2-4*h*t; if t>0.25 and t<=0.5 then x0 = xc-w/2+4*w*(t-0.25), y0 = yc-h/2; if t>0.5 and t<=0.75 then x0=xc+w/2, y0=yc-h/2+4*h*(t-0.5); if t>0.75 then x0=xc+w/2-4*w*(t-0.75), y0=yc+h/2;

    So far, x0 and y0 indicate the location of the ant ignoring the rotation. Finally we need to rotate. I’m assuming the rotation is about the center (xc, yc) of the rectangle, wherever it is as the moment; in principle you can rotate about other points but I don’t think this is what you’re after.

    So…
    x1 = xc + (x0-xc)*cos(th) + (y0-yc)*sin(th);
    y1 = yc – (x0-xc)*sin(th) + (y0-yc)*cos(th);

    And that’s it: (x1, y1) is where the ant needs to be.

    If you’re familiar with AE expressions and controls you should be able to use these formulas to make your ant. Good luck,

    – A. A.

  • Filip Vandueren

    October 30, 2005 at 12:48 pm

    I would do a script as mentioned for the position, but rotation and movement can much easier be achieved by parenting the ant to the square.

  • Mike Clasby

    October 30, 2005 at 5:57 pm

    A somewhat awkward (my specialty) solution works with an expression tying the ant’s position to the of the Write-on Effect (Brush Position) of the larger Rectangle. Parenting the Ant to the rectangle and then precomp both layers, then time remaping the precomp. Setting a keyframe in the middle of the time remap and tying it to a slider, gives you a slider controlled Ant the crawls the edges of the larger rectangle.

  • Erin Shelby

    October 30, 2005 at 6:57 pm

    cool, thanks – I know I’ll have questions eventually, but for now I’ll try coding it in. I get it though, very very cool!

    -grey

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