Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions bounce ball from floor expression help

  • bounce ball from floor expression help

    Posted by Anthony Thomas on December 29, 2008 at 9:12 pm
    bouncesPerSecond = 1.5
    bounceStrength = 200
    decayRate = .5
    floor = thisComp.layer("floor").transform.position[1]
    bounceOffset = Math.abs(Math.cos(bouncesPerSecond * time * 2 * Math.PI))
    y = bounceStrength * bounceOffset/Math.exp(decayRate * time)
    floor = floor - (height/2)
    [position[0],floor] - [0,y]
    

    Above is an expression that bounces a ball from a floor. This is from the book After Effects Expressions by Marcus Geduld

    My problem here is with the variable called height. Is there such a variable in AE java script?

    TONY T

    Anthony Thomas replied 17 years, 7 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    December 29, 2008 at 9:23 pm

    That would be the height attribute of the layer to which the expression is applied.

    Dan

  • Anthony Thomas

    December 30, 2008 at 1:51 pm

    Hey thanks but I have one more thing.

    When I copy and paste this expression into AE I get an AE warning:
    invalid numeric result(divide by zero?)
    Expression disabled.
    Error occurred at line 7.
    Comp: “ball and floor”
    Layer: 1(“ball”)
    Property: ‘Position’

    line 7 is the height/2 statement. Can you see the error? Is it trickling down or is it height/2.

    TONY T

  • Dan Ebberts

    December 30, 2008 at 2:04 pm

    Try putting a semi-colon at the end of line 7. Actually, it’s a good idea to put them at the end of each line.

    Dan

  • Anthony Thomas

    December 30, 2008 at 2:14 pm

    Hmmm. This javascript is not as forgiving as the other. Seems my habits doing javascript inside web applications are doing me in with AE3. Thanks again, I will use semi-colons. And thanks for responding so quickly.

    TONY T

  • Anthony Thomas

    December 30, 2008 at 3:15 pm

    Aha. It seems that you are better off without the seventh line. If the anchor point for the floor layer is set at the top of the floor and the anchor point for the ball is set at the bottom of the ball, the ball will always bounce from the floor, independent of where the floor is in the comp. The seventh line enforces the floor being placed halfway up the comp. Perhaps this was for presentation.

    TONY T

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