#### Archived

This topic is now archived and is closed to further replies.

# Bouncing ball revisited

This topic is 5216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Where to start.... ok im revisiting a problem that i never fully solved, well not in a correct manner (previously i used an equation to rotate the ball with time, changing the rotation and direction on contact with the floor, thus producing a bouncing effect). This was a bad way to do what i wanted and now out of curosity im revisiting the problem again.... Im basically trying to make a ball bounce on the spot indefinatly. i'm using DirectX and C++.... i have a basic timer and im using the equation: s = u*t + half a t*2 u = initial velocity t = time a = gravitational acceleration -9.81 I'm starting the ball at about 60 units above a flat plane then each frame i update 's' and apply this to the '-Y' possition of the ball object then i update 'u'. on contact with the floor im bouncing the ball by reversing 's' with a sort of bouncy factor i.e s *= -0.9 //sort of a rubber bounce effect then i just itterate from the start can anyone se anything wrong with this theory? [edited by - zavx on May 9, 2004 10:28:41 PM]

##### Share on other sites
sample code (inside a render function)

g_Sink += g_BallVelY * time + 0.5f * (g_Gravity * (time * time)));

if ( contact()) //contact was made with the floor
{
//bounce
g_Sink *= -0.9f; //bounce amount
}
g_BallPosY += g_Sink;

g_BallVelY += g_BallVelY * time;

using the above, the ball is ok for about 2 or 3 bounces then the bounce height and speed goes out of control...

##### Share on other sites
Perhaps it should be:

g_BallVelY += g_Gravity * time;

##### Share on other sites
tryed both ways but i cant get the bounce to be consistant.... i have an excell version of a bouncing ball from a friend whos studying graphics and my calculations are exactly the same.. yet its not working at expected in DX....

##### Share on other sites
what i would use is "v = u + at" where u is the start speed v is final speed, a is acceleration and t is time. Then when the ball hits the ground just increase U back to just below the value you started with to simulate the ball losing energy.

##### Share on other sites
changed it a little.

g_Sink += g_BallVelY * time + (0.5f * g_Gravity * time * time );		if ( contact()) //contact was made with the floor	g_Sink *= -0.9f; //bounce amount (0.9 = rubber 0.0 = sand)	g_BallPosY += g_Sink;

this works in a fashion, by that the ball bounces just a little too fast so i guess i just have to implement a reliable timer and thats it......

Does anyone have any good book references for this sort of thing? or more specificaly a bouncing ball example that i can see an alternative method?

##### Share on other sites
the best thing to do is i think to look up on the concept of velocity, acceleration in a textbook or some physics site.

step 1 : update the position

x = x + velocity*time + 0.5*acceleration*time*time

step 2 : update the velocity

v = v + acceleration*time

if collided with floor, change sign of velocity

1. 1
2. 2
JoeJ
20
3. 3
frob
18
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632204
• Total Posts
3004755

×