Trying to Bounce a Ball Using an Expression and Sliders
I'm trying to create an expression that gets values from sliders and uses them to create a ball bouncing animation. I've created two separate expressions that each produce a result that I'm looking for, but combining them produces an animation graph that is entirely unintelligible. Looking for someone to hopefully point out where I am going wrong.
I'm using three sliders to create the animation, they are 'Bounce Freq' (the number of times the ball bounces per second), 'Bounce Decay' (A percentage of how much of the bounce's height is maintained from one bounce to the next), and 'Bounce Initial Height' (the number of pixels above the 'ground' that the animation starts from).
The first expression I created was used to create the sin wave of the ball bouncing. When applied to the Y Position of my ball layer, it bounces with the correct frequency at the correct height for an indefinite amount of time. The expression is as follows:
The second expression is meant to be used to control the height of each bounce. I applied this expression to the Source Text property of a text layer for testing purposes. It correctly outputs the height in pixels of each bounce, halving each time the ball touches the ground. The expression is as follows:
Both of these expressions work correctly on their own, but when I combine them I get an entirely different result. The combined expression is as follows:
Can anyone help me with this and point me to where I went wrong? Thanks!
Took me a minute to notice, but the variable freq has .MathPI used in one of the expressions, and not in one of the others.
Excellent, Thank you! Moving the Math.PI to the different part of the expression did indeed fix the problem I was having with the periods of the two expressions not lining up. However, I have noticed a new problem that I was unable to observe beforehand.
The part of the expression that counts the number of times the ball has bounced (this part:)
doesn't count correctly except when the Bounce Frequency slider is set to an odd whole number (3, 5, 7, etc). When set to an even number, the count goes up when the ball is at the highest point in its arc, instead of when it contacts the ground. Having a decimal value causes the same effect (ie, if the frequency is set to 3.25, the count will increment when the ball is 1/4 completed in its arc).
I'm again at a bit of a loss, so could someone help point me in the right direction? Thanks!