Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Simulate chasing over a terrain

  • Simulate chasing over a terrain

    Posted by Tim Johnson on December 19, 2020 at 2:52 pm

    I’ve got a pointer that stays in the center of a comp, and a shape that wiggles around within the bounds of the comp. The pointer is always looking at the wiggling shape using this expression:

    target = thisComp.layer("Target");
    delta = thisLayer.toComp([0,0]) - target.toComp([0,0]);
    radiansToDegrees(Math.atan2(delta[1],delta[0])) + value

    What I’d like to do next, is have a texture underneath moving in the opposite direction to the pointer to simulate the pointer ‘chasing’ the shape around a terrain. Ideally involving change in speed too. I’m not sure where to start with it though, any help would be much appreciated. Cheers.

    Dan Ebberts
    replied 5 years, 4 months ago
    2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    December 19, 2020 at 7:54 pm

    Maybe something like this applied to the Offset Turbulence parameter of Fractal Noise (or the position property of a large texture layer):

    refPoint = [thisComp.width/2,thisComp.height/2];

    distanceFactor = 2;

    delta = thisComp.layer("Target").position - refPoint;

    value - delta*distanceFactor

  • Tim Johnson

    December 19, 2020 at 11:11 pm

    Hey Dan, that’s definitely on the right track. The problem with that though is that the terrain stops moving when the target does, I’d like the terrain to be moving continuously and only angled via the direction of the pointer/target. The speed variation could be that the terrain moves faster when the target is closer to the pointer (as if it was catching up).

    I have a feeling the answer may lie somewhere in your guide here:

    https://www.motionscript.com/articles/speed-control.html

    Although I’m not sure how to integrate the concepts here, because it feels like it needs ‘time’ in play to keep it moving constantly (with no keyframes).

  • Dan Ebberts

    December 20, 2020 at 12:52 am

    Yeah, OK. Maybe something like this then:

    maxSpeed = 10;

    minSpeed = 0;

    maxDistance = 500;

    target = thisComp.layer("Target").position;

    pointer = thisComp.layer("Pointer").position;

    accum = d = [0,0];

    f = timeToFrames(time);

    for (i = 0; i <= f; i++){

    t = framesToTime(i);

    d = target.valueAtTime(t) - pointer.valueAtTime(t);

    factor = linear(length(d),0,maxDistance,maxSpeed,minSpeed);

    accum += normalize(d)*factor;

    }

    value - accum;

  • Tim Johnson

    December 20, 2020 at 1:00 am

    that’s so cool Dan, thank you!

    I will take the time to dissect and absorb this. It means a lot.

    One thing, is there a reason the ‘accum’ variable needs a second name ‘d’? Does that establish two separate variables?

  • Dan Ebberts

    December 20, 2020 at 1:07 am

    Just a lazy way to initialize two variables to the same value.

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