Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Count bounces of DVD logo

  • Count bounces of DVD logo

    Posted by Ana Caballero on May 3, 2022 at 10:47 pm

    Hey guys,

    I used the expression for the bouncing DVD logo i found here on CreativeCow.

    I am trying now to add a counter that detects each collision.

    I managed to detect a direction change for my logo, but I am failing at counting the detections without overwriting the added number.

    My set-up looks like this:

    a var switchDirection will look at the position of the logo and switch from 0 to 1 or 1 to 0 each time the direction changes.

    A counter looks at that sswitch and compares the valueAtTime(time) and valueAtTime(time-1) to see if a change happened.

    var sswitch = effect("Switch")("Kontrollkästchen");
    if(sswitch.valueAtTime(time)==sswitch.valueAtTime(time-(1/25))){
    	value;
    } else {
    	value+1
    }

    My problem is now that instead of counting up, the counter is always is setBack to 0 one frame after the direction change.

    I can see why my code doesnt work, but I cant figure out a way to bypass it.

     

    Anyone any idea how to do it?

     

    Thanks in advance.

     

    Filip Vandueren replied 4 years, 4 months ago 2 Members · 1 Reply
  • 1 Reply
  • Filip Vandueren

    May 4, 2022 at 9:33 am

    Hello Ana,

    I’m assuming you used this expression of mine forma few years ago:

    hSpeed= 1111;
    vSpeed= 345;
    hMargin= 150;
    vMargin= 75;
    cw=thisComp.width - hMargin*2;
    ch=thisComp.height -vMargin*2;
    // calculate the layer moving at a constant speed
    x = value[0] - hMargin + time*hSpeed;
    y = value[1] - vMargin + time*vSpeed;
    // keep the layer in bounds
    x = Math.abs(x);
    x%=2*cw;
    x = x>cw ? (2*cw)-x : x;
    y = Math.abs(y);
    y%=2*ch;
    y = y>ch ? (2*ch)-y : y;
    [x,y]+[hMargin,vMargin]

    You can count the bounces by using similar Math instead of actually look at the values of the keyframes.

    this would work:

    hSpeed= 1111;
    vSpeed= 345;
    hMargin= 150;
    vMargin= 75;
    cw=thisComp.width - hMargin*2;
    ch=thisComp.height -vMargin*2;
    startPos = position.valueAtTime(0);
    // calculate the layer moving at a constant speed
    x = startPos[0] - hMargin + time*hSpeed;
    y = startPos[1] - vMargin + time*vSpeed;
    hBounces = Math.floor(x/cw);
    vBounces = Math.floor(y/ch);
    totalBounces = hBounces + vBounces;

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