Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scaling the position travelled

  • Scaling the position travelled

    Posted by Ole Sturm on April 23, 2014 at 4:09 am

    Hi. I’ve been noodling around with this for some time and sort of have a solution… but not quite. Here’s the scenario – I often track filmed footage in order to obtain a realistic camera wobble – I then apply these keyframes to a parent null. However, sometimes the wobble is simply too much and I want to scale it down (or up when the wobble is not enough). I’ve tried to come up with an expression which is applied to the target layer’s position, which references the layer with the tracking keyframes. The expression also references an expression control called “scale”, which controls the amount by which the distances are scaled. This expression works fine as long as the tracked item is moving around the centre of the frame – if it’s off to one side it falls over.

    I’d hugely appreciate it if someone on this forum were able to point me in the right direction.

    Many thanks.

    x = thisComp.layer("tracked item").transform.position[0]; // the value of the tracked layer
    y = thisComp.layer("tracked item").transform.position[1];
    cntrX=thisComp.width/2; // calculates the centres of the comp
    cntrY=thisComp.height/2;
    diffX=x-cntrX; // calculates the distance of the tracked layer moved from the centre
    diffY=y-cntrY;
    if (effect("scale")("Slider")>1) { // checks whether the scaler is negative or positive
    [x+(diffX*effect("scale")("Slider")), y+(diffY*effect("scale")("Slider"))]
    } else {
    [x-(diffX*effect("scale")("Slider")), y-(diffY*effect("scale")("Slider"))]
    }

    Ole Sturm replied 12 years ago 2 Members · 10 Replies
  • 10 Replies
  • Dan Ebberts

    April 23, 2014 at 5:06 am

    Just thinking off the top of my head here, it seems like you need a center reference. I guess you could eyeball an average and hard code it, or calculate it based on where the track points at time zero. (Or you could even create an expression to calculate the average over all frames and then convert that to keyframes). In any case, your expression would do its calculation based on the current distance of the center from the reference center.

    Dan

  • Ole Sturm

    April 23, 2014 at 10:34 am

    Ahhh Dan, ever the wanna-be expressioneers knight in shining armour. When you put it the way you’ve put it, it seems so much clearer. The “average” approach is tempting but I have no idea where I would need to start with that. Are you able to point me in the right direction?

    As ever, thanks so much for your help over the years.

  • Dan Ebberts

    April 23, 2014 at 4:27 pm

    The details would depend on how you have things set up, but in general, getting the average of a point over the duration of the comp would go something like this:


    point = thisComp.layer("Null 1").transform.position;

    accum = [0,0];
    fTotal = timeToFrames(thisComp.duration);
    for (f = 0; f < fTotal; f++){
    accum += point.valueAtTime(framesToTime(f));
    }
    accum/fTotal

    You could extend the idea to include multiple points if what you have to work with are the corners of a rectangle (just add all fours points to the accumulator in the loop, then divide by (fTotal*4) at the end). Then you’d probably want to convert the expression to keyframes so you don’t have to do that calculation on every frame. Something like that.

    Dan

  • Ole Sturm

    April 23, 2014 at 9:41 pm

    Fantastic Dan, thanks very much – that’ll keep me going.

    Best regards.

    p.s. loving your Motion Monkey plugin.

  • Dan Ebberts

    April 23, 2014 at 9:49 pm

    >p.s. loving your Motion Monkey plugin

    Thanks–that was a fun project.

    Dan

  • Ole Sturm

    April 23, 2014 at 11:19 pm

    Hi Dan,

    Ok. just having a play around with that but am not having any joy (I’m probably misunderstanding your approach). To test the expression I added keyframes to “Null 1” and then applied the expression to a layer’s position. If you understand it correctly skewing Null 1’s keyframes off centre should affect the position of the layer, is that right?

    As for the plugin, keep them coming – I for one am certainly up for them.

  • Dan Ebberts

    April 23, 2014 at 11:38 pm

    The expression should average the position of the null over the duration of the comp. So if you move all the keyframes towards one corner of the comp, the layer should move in that direction. Note that the layer’s position won’t animate, it just sits at the average of all past, present, and future frames.

    Dan

  • Ole Sturm

    April 29, 2014 at 12:47 am

    Hi Dan,

    Sorry for the delay in getting back to you. Got it working – thanks a stack… much appreciated.

    cheerio

    Ole

  • Ole Sturm

    April 29, 2014 at 1:18 am

    FYI, here’s what I’ve ended up with:

    point = thisComp.layer("tracked").transform.position; //"tracked" is the layer which contains the tracking data
    accum = [0,0];
    fTotal = timeToFrames(thisComp.duration);
    for (f = 0; f &lt; fTotal; f++){
    accum += point.valueAtTime(framesToTime(f));
    }
    centre=accum/fTotal;
    distance=thisComp.layer("tracked").transform.position;
    difference=distance-centre;
    if (effect("scale")("Slider")>1) { //the "scale" effects is a slider expression control which scales the tracked data up or down
    distance+(difference*effect("scale")("Slider"));
    } else {
    distance-(difference*effect("scale")("Slider"));
    }

  • Ole Sturm

    April 29, 2014 at 1:45 am

    Next question now is how to apply your expression to averaging the rotation values of a tracked camera wobble?

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