Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to make a boat “ride” on top of generated waves?

  • Max Palmer

    May 11, 2012 at 1:38 pm

    Actually the expression you gave me earlier works exactly the way I want. He will only be moving about halfway across the screen. Now, I just have to add the rotation expression.

    Thank you for writing this for me- I’d like to learn expressions better, but the syntax is hard for me to swallow, and I have no experience with anything similiar, such as javascript.

    How do I go about baking an expression? (if it’s too hard to explain, I’ll just google it.) Is that the same as pre-rendering a comp?

    Again, thank you!

  • Dan Fredley

    May 11, 2012 at 1:41 pm

    To bake expressions:

    Select the property you would like to bake and go up to Animation>Keyframe Assistant>Convert Expression to Keyframes.

    Dan Fredley

  • Max Palmer

    May 11, 2012 at 1:51 pm

    Very cool. Thanks again!

  • Max Palmer

    May 11, 2012 at 2:00 pm

    Ah, one sec. The rotation expression you wrote is for if I were to pre-comp the boat and waves, which I’m not doing. I can’t figure out how to take that expression and make it apply to the boat layer that I already have the position expression working on.

    Is this rotation expression meant to be applied directly to the boat layer’s rotation property? Or is it meant to be applied to the wave layer, and thus targets the boat layer instead?

  • Dan Fredley

    May 11, 2012 at 2:05 pm

    Apply the rotation expression to the boat rotation. You’ll have to change the “target” variable by pickwhipping the boat layer and the “sample” variable by pickwhipping the ocean layer.

    Dan Fredley

  • Max Palmer

    May 11, 2012 at 3:43 pm

    Did that, but now it says “target.toWorld” is undefined. I’ve been combing through the script, and messing with this a bit, and I can’t figure it out.

  • Max Palmer

    May 11, 2012 at 3:49 pm

    This is how I have it. All I did was change the target, and sample variables.

    target = transform.rotation; targetWorldPos = target.toWorld(target.anchorPoint); sample = thisComp.layer("Waves"); offset = -10; for (i = 0; i < height; i++){ if (sample.sampleImage([clamp(targetWorldPos[0]+offset,0,thisComp.width), i], [0.5, 0.5], true)[3] > 0){ top = [0,i]; break; } else { top = [0,thisComp.height]; } } newWorldPos = target.fromWorld(target.toWorld(top)); offsetPos = [target.position[0]+offset,newWorldPos[1]]; for (i = 0; i < height; i++){ if (sample.sampleImage([clamp(targetWorldPos[0],0,thisComp.width), i], [0.5, 0.5], true)[3] > 0){ top = [0,i]; break; } else { top = [0,thisComp.height]; } } targetWorldPos = target.fromWorld(target.toWorld(top)); boatPos = [target.position[0],targetWorldPos[1]]; radians = Math.atan2(boatPos[1] - offsetPos[1],boatPos[0] - offsetPos[0]); radiansToDegrees(radians);

  • Dan Fredley

    May 11, 2012 at 3:53 pm

    The target variable is wrong–you should place the whole expression on the boat rotation not assign the variable “target” to the rotation.

    It should read something like this according to your layer name:

    target = thisComp.layer("Boat");

    You can also just write:

    target = thisLayer;

    By the way, the offset is for going right to left. If the boat is going from left to right it might be better to change it to 10 instead of -10.

    Dan Fredley

  • Dan Fredley

    May 11, 2012 at 4:05 pm

    Here’s my AE CS5.5 rendition for reference:

    BoatWaveWarp

    Dan Fredley

  • Max Palmer

    May 11, 2012 at 4:22 pm

    Ah, unfortunately they haven’t bumped us up to CS5.5 or CS6 here.

    So all the errors have gone away, but the boat’s rotation property doesn’t seem to be effected in any way. I’ve been scouring through this, rearranging variables and things to see if I can get it to work, but I can’t make sense of it enough to figure it out.

    target = thisLayer;
    targetWorldPos = target.toWorld(target.anchorPoint);
    sample = thisComp.layer("Waves");
    offset = -10;

    for (i = 0; i < height; i++){ if (sample.sampleImage([clamp(targetWorldPos[0]+offset,0,thisComp.width), i], [0.5, 0.5], true)[3] > 0){ top = [0,i]; break; }
    else { top = [0,thisComp.height]; } }

    newWorldPos = target.fromWorld(target.toWorld(top));
    offsetPos = [target.position[0]+offset,newWorldPos[1]];

    for (i = 0; i < height; i++){ if (sample.sampleImage([clamp(targetWorldPos[0],0,thisComp.width), i], [0.5, 0.5], true)[3] > 0){ top = [0,i]; break; }
    else { top = [0,thisComp.height]; } }

    targetWorldPos = target.fromWorld(target.toWorld(top));
    boatPos = [target.position[0],targetWorldPos[1]];
    radians = Math.atan2(boatPos[1] - offsetPos[1],boatPos[0] - offsetPos[0]); radiansToDegrees(radians);

Page 2 of 3

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