Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions position detection

  • position detection

    Posted by Guillaume Charron on October 29, 2012 at 4:21 pm

    Hi,
    I need to move some layers according to the position of another layer. To be more precise, when the layer “A” is moving towards layers “B”, “C”, “D”, etc, “B”-“C”-“D” needs to move out from layer “A”… Like 2 magnets on the same positive sides.

    It would be nice if the runaway layers would go around the same position (but not the exact same position).

    Guillaume Charron replied 13 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Daniel Russell

    October 29, 2012 at 10:46 pm

    The first idea that comes to mind is this strategy. Basically, you want to
    have a scaryDot and a crowdNull. All the important chasing/running away stuff happens between just those two objects.

    Relatively simple expressions in the individual dots that form the crowd will merely offset their position from the crowdNull.

    The first simple way of seeing this (before sprucing it up) is this: simply have the crowdNull run away from the scaryDot in two different, but blended, manners. The first manner in which it runs away is a bee line that is simply in the same direction as that from which it is chased. The second manner is veering to avoid colliding with the edges of your composition. Blend the two together using whatever mathematical factors look good.

    Hereʻs a more detailed breakdown of the steps in the code.

    1) Use a null object that is roughly in the center of the swarm.
    2) Use expressions in each of the dots to offset from the null, with some randomness using random() and associated functions. Alternatively, you can simply parent all the dots to the null and use wiggle to move them relative to it.
    3) Now, the running motion only has to happen for the null, and all the dots will follow. This is the challenging part.
    4) Calculate the unit direction vector between the scary dot and the null controller by using normalize(sub(crowdNull.position, scaryDot.position)). You will use this vector to determine the general *direction* that the crowdNull runs (and thus the crowd of dots).
    5) Now you need to account for speed, and multiply that by the unit direction vector to obtain velocity. The speed will depend on two things: a) acceleration b) the speed of the scaryDot itself, which you determine by looking at how far it has moved since previous frame to get pixels/frame.
    6) Multiply the unit direction vector by the speed you calculated using beeLineDelta = mul(direction, speed).
    7) As this deltaPosition causes the crowdNull to approach the edge of the comp, you need to veer away from the edge. Thatʻs the biggest “gotcha” in this code. Letʻs take an example. If the vector from the scaryDot to crowdNull is leaning left, then the crowdNull should probably veer left as it approaches the edge of the comp, to avoid slamming the wall.

    If I get time, I will post extracts from the code I have in mind. Itʻs, sadly, a little complex. 😉

  • Guillaume Charron

    October 30, 2012 at 3:08 pm

    Wow! Good explanation. 🙂 I have added a video of what I have done manualy with keyframes. You’ll have a better idea of my needs. If you can help it would be nice. If not, thanks anyway.

    cathing sheeps

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