Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Playing a layer only when it moves

  • Playing a layer only when it moves

    Posted by Cameron Clark on January 13, 2016 at 9:52 pm

    Hi there, I’m stumped and wondering if anyone has a solution to this.

    I’ve got a layer that starts with a single frame of a character standing still, and then plays a really simple walk loop til the end of the clip. I would love to be able to write an expression (or through another method if there’s one I’m not thinking of) that would hold on that still frame when the layer is still, but if I’ve animated the position of the layer, it plays the clip at normal speed, so I get a very quick and easy way to make it look like the character is walking when he’s moving and standing when he’s still.

    I can obviously do it by hand by keyframing the timeRemap value, but I would love to automate it because I’m planning on having dozens of these little characters all running around and it’ll get messy fast.

    I’ve tried an if/then statement applied to the timeRemap value that compares the position to the position in the previous frame and if it returns that they are the same it sets the timeRemap attribute to 0, but plays the current value of timeRemap if they are not the same, which looked like this (this is just the x values for now to keep it simple):

    if (transform.position[1] == transform.position.valueAtTime(time- 1/(thisComp.frameDuration))[1]){
    0;
    }else{
    value;
    }

    When the layer is still, this works to set the timeRemap to 0, but when it is moving it sometimes displays the correct frame, and sometimes jumps to 0. I cant for the life of me figure out why it doesn’t constantly play the correct frame. Anyone have any ideas why? Or maybe another method to try?

    Dan Ebberts replied 10 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    January 13, 2016 at 10:45 pm

    It’s a little tricky, and the details will depend on how you have things set up, but the key, I think, is that when the character is walking, you have to calculate how long ago that began. So, using valueAtTime(), you need to go back in time and find the most recent frame where the character went from not walking to walking, calculate the elapsed time since then, and use that to determine where you are in the walk cycle. A bit of work, but do-able.

    Dan

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