so apparently my math calculations must be way off,I am trying to create the physics for a ball bouncing each time it's dropped,the Y access in SDL starts at the top and is 0 and goes downwards towards the end of the window given your window height,I know roughly each time a ball is bounced it's height will be approx half that of it's previous height,so lets say when my ball is dropped from the height of 23 well half of that is 11.5 but obviously that won't work so I thought of the opposite,multiplication
so ballDroppedY* = 2 will be 23 by 2 which equals 46 so half of 46 is 23,but this may hold true it doesn't hold true for my game as this is still not half the distance from the highest point it was dropped and the minimum point(the platform)
could anyone point me in the right direction as to where and how my calculations are wrong?
to really sim the physics you need to iterate 'time' in seconds (does not have to match real seconds) and calculate the position. When it hits the ground it gets an impulse back up that slowly drains off by the negative acceleration of gravity until it falls again, and so on.
so at time zero, distance from where you were is zero, initial velocity is zero, and gravity is g. so its position is 1/2g*0 + 0= 0 … it hasn't moved.
time 1, position is 1/2g*1*1 + 0.
time 2, position is 1/2g*2*2+0..
until that is equal to the distance traveled to impact, eg 23.
if g is 10 pixels /sec/sec, then (this makes 1 meter 1 pixel roughly)
it will impact in about 2.1 seconds. Likely you will adjust this so a meter is many pixels so it is more interesting, but you can do that part yourself.
when it reaches 23 distance, it impacts (don't even need to check collision, its known) and you do the same math except with initial velocity. Say the initial velocity is 15.
time = 0 (starting over every time it impacts) as above its zero, unchanged.
time 1, d = 1/2g*1*1+15*1
and so on. after a bit it will stop going up, slow, go back down, impact, and repeat this. the first iteration is the only one that is odd, because it starts in the air instead of on a bounce. all the others are the same.
at some point the initial velocity is very low and you should stop; your sim might go on for a long, long time trying to iterate fractions of pixels (like trying to walk half way to something every loop but never reaching it forever).
> I know roughly each time a ball is bounced it's height will be approx half
> that of it's previous height, so lets say when my ball is dropped from the
> height of 23 well half of that is 11.5 but obviously that won't work so I
> thought of the opposite,multiplication (¿?)
> so ballDroppedY* = 2 will be 23 by 2 which equals 46 so half of 46 is 23,but
> this may hold true it doesn't hold true for my game
¿what?
you want to divide by two, so you instead multiply
I don't understand you
the ball doesn't reach its initial height because some of its energy was dissipated as heat in the collision (no air resistance, don't remember the equations)
so you dropped the ball from height `h', it travelled a time `t' and reached a velocity of `v_f' upon impact
In constant acceleration h = 1/2 v_f t (a right triangle of area `h' with `t' for base and `v_f' for height, the acceleration is the tangent of the angle)
you want it to reach half that height, so you need a similar triangle (same acceleration) with half the area 1/4 v_f t = 1/2 \alpha v_f \alpha t -> \alpha = 1/sqrt(2) ~ 0.707
so, after the collision, your velocity will be 0.707v, and it 0.707t you'll reach the peak at half the height from which you started.