Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Inverse Magnetism

  • Posted by Johnnyfix on May 3, 2007 at 3:29 am

    Suppose I have a cluster or cloud of 3d layers, all of which are facing the same direction (the camera), is there a way to rig it so as I have my camera push through the cloud of layers, each layer will react to the proximity of the camera by moving away from it; reverse magnetism.

    In other words, imagine an invisible sphere around my camera that nudges these layers out of the way as the camera pushed through the crowd of layers.

    Ideally, each layer would move in a unique direction relative to the camera. essentially, each layer would move in the direction of displacement from the camera’s path.

    Does any of this make sense? Is it possible?

    Thanks for your help.

    Johnnyfix replied 19 years ago 4 Members · 8 Replies
  • 8 Replies
  • Colin Braley

    May 3, 2007 at 6:40 am

    This is definetly possible, and is a very neat idea, I never thought of doing somehting like this. Assuming there is no parenting goign on, this expression should work for you:


    //begin expression
    maxDisplacement = 500;
    maxDistance = 700;
    //--
    cameraPos = thisComp.activeCamera.position;
    thisPos = position;
    vec = cameraPos - thisPos;
    distance = length( vec );
    dispAmt = ease(distance , 0 , maxDistance, maxDisplacement , 0);
    normalizedVec = normalize( vec );
    position - (normalizedVec * dispAmt)
    //end expression

    What this does is as the camera moves closer to a layer, the layer moves away, in the direction from the camera to the center of the layer. If you want the layers to move away farther, adjust maxDisplacement, and if you want the layers to begin repelling at a closer distance to the camera, make maxDistance smaller. Enjoy.

    ~Colin

  • Johnnyfix

    May 3, 2007 at 8:10 am

    Thanks for your help!
    This might be a stupid question

    Do I apply this expression the position property of each layer to be influenced by the camera?

  • Filip Vandueren

    May 3, 2007 at 10:39 am

    Nice expression, Colin,

    to Johnny:

    yes, you’ll have to apply it to each layer’s position.

  • Johnnyfix

    May 3, 2007 at 3:56 pm

    Okay, great! I just tested it and it looks awesome.

    One last question:

    Right now, the layers are influenced in all three dimensions. Is there a way to restrict the movement of the layers to just the X and Y axis?

    Thanks again for your help.

  • Colin Braley

    May 4, 2007 at 1:28 am

    [Filip Vandueren] “Nice expression, Colin,”

    Thanks Filip

    [johnnyfix] “Is there a way to restrict the movement of the layers to just the X and Y axis?”

    Sure, I think this expression below should do it, but I don’t have AE at the computer I’m at, so I cant test it to be sure. Apply this expression to the position property of every layer you want to be affected:

    //begin expression
    maxDisplacement = 500;
    maxDistance = 700;
    //–
    cameraPos = thisComp.activeCamera.position;
    thisPos = position;
    vec = cameraPos – thisPos;
    distance = length( vec );
    dispAmt = ease(distance , 0 , maxDistance, maxDisplacement , 0);
    normalizedVec = normalize( [vec[0] , vec[1]] );
    position – (normalizedVec * dispAmt)
    //end expression

    If this dosen’t work, let me know.
    ~Colin

  • Julian Sixx

    May 4, 2007 at 4:31 am

    Hi

    //begin expression
    maxDisplacement = 500;
    maxDistance = 700;
    //–
    cameraPos = thisComp.activeCamera.position;
    thisPos = position;
    vec = cameraPos – thisPos;
    distance = length( vec );
    dispAmt = ease(distance , 0 , maxDistance, maxDisplacement , 0);
    normalizedVec = normalize( [vec[0] , vec[1]] );
    position – (normalizedVec * dispAmt)//end expression

    The above expression gives me a division error on line 11

  • Colin Braley

    May 4, 2007 at 5:16 am

    Sorry about that, it will give you an error if the camera is at the same position as a layer…try this revised version:


    //begin expression
    maxDisplacement = 500;
    maxDistance = 700;
    //--
    cameraPos = thisComp.activeCamera.position;
    thisPos = position;
    vec = cameraPos - thisPos;
    distance = length( vec );
    dispAmt = ease(distance , 0 , maxDistance, maxDisplacement , 0);
    normalizedVec = normalize( [vec[0] , vec[1]] );
    try{
    position - (normalizedVec * dispAmt)
    }catch(e){
    position
    }
    //end expression

    ~Colin

  • Johnnyfix

    May 5, 2007 at 7:53 pm

    Thanks so much for all your help. These expressions work great!

    You guys rock.

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