Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Stop the position of a Layer at a certain point

  • Stop the position of a Layer at a certain point

    Posted by Julian Meyer on November 4, 2015 at 3:17 pm

    Hey,

    this is my first post and I am very new to expressions.
    I have been looking all over for a solution to my problem but I just can’t wrap my head around it:

    I want to be able to move a bouncing box from left to right and have the x Position stop whenever it “hits” the ground.
    I thought I could parent the jumping box to a null, move that null on the x axis and give it an expression that reads the y Value of the box and stops moving when the box reaches the ground. So far I have not succeeded in doing so.
    Is this totally the wrong way to think about it?

    Kalleheikki Kannisto replied 10 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    November 7, 2015 at 6:44 pm

    To get a bouncing box you’d likely want the whole motion to happen through an expression where you give the initial speed, direction, gravity and ground height and let the expression create the motion.

    A box that stops when it hits the ground is not a bouncing box at least not in the sense of how a ball would bounce. It might be a jumping box in the sense like a frog jumps. But there is a problem with this approach in that when you bring the null back up above the ground plane, the box will immediately jump to the position of the null, it won’t continue from where it hit the ground.

    Well, I guess I’ll have to answer your question with a question: Do you want the box to bounce (i.e. immediately ricochet back into the air when hitting the ground) or do you want it to jump, hold, then jump again?

    For a really simple solution, you could do it with a time-based expression which uses time as the x position and the absolute value of sine of time for the y position with suitable multipliers. That would give a perfectly bouncy result. You could also make the multipliers decrease over time to get a diminishing bounce as the kinetic energy dissipates.

    Thus, in it’s simplest form something like this for box position:

    x=100*time;
    y=750-250*Math.abs(Math.sin(time));
    [x,y]

    wherein the horizontal speed is controlled by the multiplier for x (100 in this case), the ground position is 750 and the height of bounce is 250. The example is a slow bounce. If you want the bounces be more frequent, add a multiplier to the time (inside the parenthesis) in the y expression.

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