Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Hundreds of isometric characters walking around !

  • Hundreds of isometric characters walking around !

    Posted by Matt Jones on May 30, 2024 at 3:52 pm

    Long time listener, first time caller here.

    I’m hoping someone can either help me with specific expressions or come up with an altogether better idea !

    I have an isometric world with loads of isometric characters walking around. When I say loads, I mean hundreds. They all need to be walking around and ‘bouncing’ off walls. I have animated walk cycles for each of the 4 directions they travel. (top left, top right, bottom left, bottom right).

    I was thinking a plugin like Newton would do the job for placement and movement, but they need to look like they are walking in the direction they are traveling, and because its an isometric view, the ‘orient along path’ wont work. So ‘I think’ I would some how need to snap the animation to the different walk cycles depending on the direction they’re traveling, (but then newton fires them in all directions so im not sure if thats the best solution.)

    Can you use expressions to detect what direction a layer is traveling and then switch its precomp animation to match that? :S

    Or is there an all together much better way of doing it?

    Thanks (and sorry!)

    Dan Ebberts replied 2 years, 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 30, 2024 at 4:35 pm

    >Can you use expressions to detect what direction a layer is traveling and then switch its precomp animation to match that?

    In general, yes. If you’re generating the movement by animating the position property, for example, you can look at the position property’s velocity and determine which quadrant the direction of the movement is in by the sign of the x and y components: upper right (+, -), lower right (+, +), lower left (-, +) or upper left (-, -). That could be used to determine which section of a time remapped walk cycle plays (or which layer in a pre-comp is visible). Definitely do-able, with a number of options.

  • Matt Jones

    May 31, 2024 at 10:39 am

    That’s encouraging!

    I’ll share what I’ve got, it kind of works… so far at least.

    The best I can get (with help from a robot friend and a sledge hammer) is below.
    I’ve gone for 8 directions of walking.

    So, on my character layer there’s a slider Slider effect called ‘Direction’ with this expression

    // Store the current position
    var currentPosition = position.value;
    // Store the previous position
    var previousPosition = position.valueAtTime(time - thisComp.frameDuration);
    // Calculate the difference in position to determine the direction
    var deltaX = currentPosition[0] - previousPosition[0];
    var deltaY = currentPosition[1] - previousPosition[1];
    var directionNumber = 0;
    if (deltaX == 0 && deltaY == 0) {
    directionNumber = 0; // No movement
    } else {
    var angle = Math.atan2(deltaY, deltaX) * 180 / Math.PI;
    if (angle >= -22.5 && angle < 22.5) {
    directionNumber = 4; // Right
    } else if (angle >= 22.5 && angle < 67.5) {
    directionNumber = 8; // Down-Right
    } else if (angle >= 67.5 && angle < 112.5) {
    directionNumber = 2; // Down
    } else if (angle >= 112.5 && angle < 157.5) {
    directionNumber = 7; // Down-Left
    } else if (angle >= -67.5 && angle < -22.5) {
    directionNumber = 6; // Up-Right
    } else if (angle >= -112.5 && angle < -67.5) {
    directionNumber = 1; // Up
    } else if (angle >= -157.5 && angle < -112.5) {
    directionNumber = 5; // Up-Left
    } else {
    directionNumber = 3; // Left
    }
    }
    // Return the current position to avoid breaking the position expression
    currentPosition;
    // You can see the direction number in the slider
    directionNumber;

    and then in time remap

    // Get the direction number from the Direction slider control
    var directionNumber = effect("Direction")("Slider").value;
    // Map the direction number to specific times
    // Adjust these values based on your precomp timing
    var timeMap = [0, 1, 2, 3, 4, 5, 6, 7, 8]; // Example times for each direction
    // Return the corresponding time remap value
    timeMap[Math.round(directionNumber)];

    the time remap doesn’t give those numbers but its predictably wrong which is good enough, I guess !

  • Dan Ebberts

    May 31, 2024 at 3:10 pm

    I think you’re on the right track, except that the time remapping part has to figure out how long the animation has been moving in the current direction. I haven’t tested any of this (so there may be typos), but here’s how I’d do the slider:

    v = position.velocity;
    if (v[0] == 0 && v[1] == 0){
    n = 0;
    }else{
    a = radiansToDegrees(Math.atan2(v[1],v[0])) + 180;
    if (a < 22.5){
    n = 3;
    }else if (a < 67.5){
    n = 5;
    }else if (a < 112.5){
    n = 1;
    }else if (a < 157.5){
    n = 6;
    }else if (a < 202.5){
    n = 4;
    }else if (a < 247.5){
    n = 8;
    }else if (a < 292.5){
    n = 2;
    }else if (a < 337.5){
    n = 7;
    }else{
    n = 3;
    }
    }
    n

    And here’s an attempt at the time remapping:

    s = effect("Direction")("Slider");
    timeMap = [0, 1, 2, 3, 4, 5, 6, 7, 8];
    n = Math.round(s.value);
    f = timeToFrames(time-thisComp.frameDuration);
    while (f >= 0 ){
    nPrev = s.valueAtTime(framesToTime(f));
    if (nPrev != n) break;
    f--;
    }
    t = time - framesToTime(f+1);
    timeMap[n] + t;

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