Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Jumping i Y when moving in X?

  • Jumping i Y when moving in X?

    Posted by Martin Löfqvist on December 18, 2011 at 12:53 pm

    Hi everyone,
    
    When I tried out Carl Larsen amazing tutorial the vehicle rig (big up Carl!) I came to think that the same principle could be applied to making a character “jump up” (south park style) when moved in x position.

    Though I can’t figure out how to approach this:

    1) Should this be done with a function counting a variable up to 10 and then down again, and applying that to the y-pos as long as it’s moving in x?

    2) Or using a built in function like wiggle or Math.sin?

    Anyone has any ideas for this, greatly appreciated!

    Best
    /M

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

    December 18, 2011 at 5:17 pm

    You could try something like this:

    freq = 0.5;
    amp = 15;
    x = value[0];
    y = amp*Math.abs(Math.sin(x*freq*Math.PI*2));
    value + [0,y]

    The problem is that when the character stops, the odds are that it will be above the “ground”, but it seems to work pretty well while the character is moving.

    Dan

  • Martin Löfqvist

    December 18, 2011 at 7:37 pm

    Hi Dan,

    it works. Sort of.
    First of I’m looking to seperate the position dimensions. (It should just be a matter of re-arranging the code I think).
    Then it behaves kinda odd when I’m changing the incoming/outgoing velocity of the keyframes. Whys that?

  • Dan Ebberts

    December 18, 2011 at 7:47 pm

    Basing it on horizontal distance traveled (like the tutorial) probably doesn’t work for this. You might be better off basing it on time. Here it is set up for separated y position:

    freq =2;
    amp = 15;
    y = amp*Math.abs(Math.sin(time*freq*Math.PI*2));
    value + y

    Dan

  • Martin Löfqvist

    December 18, 2011 at 7:57 pm

    Yeah,

    this is nice! Is it possible to run this only when the object is moving in x? Is it possible to get the last frames x position and compare it to the current frames x position? That way you could get that information.

  • Dan Ebberts

    December 18, 2011 at 8:06 pm

    More like this maybe:

    if (transform.xPosition.speed > 0){
    freq =2;
    amp = 15;
    y = amp*Math.abs(Math.sin(time*freq*Math.PI*2));
    }else
    y = 0;
    value – y

    Dan

  • Martin Löfqvist

    December 18, 2011 at 8:16 pm

    Dan, amazing! This seems to work.

    Very much appreciated!!

    A question regarding the solution:
    1) You are analyzing the “speed” property in xPosition. Is this the same value as you see in the graph editor? (Had no idea you could get this value!)

    2) You are writing “value – y”, is value a variable or a way to … execute the script? I never seen it before.
    

  • Dan Ebberts

    December 18, 2011 at 8:25 pm

    >Is this the same value as you see in the graph editor?

    It should be.

    >is value a variable

    “value” is just shorthand for the pre-expression value of the property hosting the expression. In this case it would be the same as using “yPosition”.

    Dan

  • Martin Löfqvist

    December 18, 2011 at 8:39 pm

    Ah I see!

    One, not so tiny problem though:
    Because it’s based on the xPosition.speed moving it to the left renders a negative speed value thus no jumping.
    Would the solution be just to look for the exact value of 0 in xPosition.speed or writing another if loop?

  • Martin Löfqvist

    December 18, 2011 at 8:44 pm

    I solved it by changing > to !== in the if loop,

    thanks for the help Dan!

    if (transform.xPosition.speed !== 0){
    freq =2;
    amp = 15;
    y = amp*Math.abs(Math.sin(time*freq*Math.PI*2));
    }else
    y = 0;
    value - y

  • Dan Ebberts

    December 18, 2011 at 8:50 pm

    It would be != not !==.

    Dan

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