Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions How to connect a shape layer to a wave shape using Math.sin()

  • How to connect a shape layer to a wave shape using Math.sin()

  • eduardo asta

    August 29, 2021 at 4:33 pm


    The ball (green) keeps the same X position all times, at the center of the comp, but its Y position goes up and down. At the same time, the wave shape layer (red) is moving from right to left (X position). It should looks like as the ball is always in the comp’s center, going up and dawn along the waves, and the red shape layer is moving from right to left.

    I was using the following expression at ball’s Y position, but it’s very hard to connect the ball’s amplitude and frequency to the wave’s X and Y displacement.

    a = 118;//amplitude

    f = .5;//frequency

    t = time – inPoint;

    value + Math.sin(t*2*Math.PI*f)*a;

    There is anybody who knows how to do that?


  • Fabrice Leconte

    September 10, 2021 at 9:28 am


    You can adjust the Y position of the ball by testing the collision with the sine wave.

    First, I tried to use sampleImage to test the collision, it worked but the rendering time was too long (more than 1 hour for a few seconds of video).

    Finally, I tried in a different way, I calculated the distance between the ball and each points of the sine wave and if the distance was lower than the ball radius it means that the sine wave collide with the ball so I adjusted the ball Y position until collision return false.

    View post on

  • eduardo asta

    September 10, 2021 at 11:30 am

    WOW! It totally works! Many thanks! I’ve just opened the AEP file and I will try to understand how did you do this.

    Thanks again!😀

  • eduardo asta

    September 11, 2021 at 4:38 pm


    I’m a beginner on JS and expressions, but I was able to understand what you did. Besides the collision stuff, you also have also created the sine path using and expression (createPath()). It is amazing. Thanks.

  • Fabrice Leconte

    September 11, 2021 at 6:41 pm
  • eduardo asta

    September 12, 2021 at 10:44 pm

    Another lighter and better version? I will dive in it. Thanks!

Viewing 1 - 6 of 6 posts

Log in to reply.

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