Results 1 to 6 of 6

Thread: bouncing ball physics.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    bouncing ball physics.

    Can someone help me out. I need the formula for a bouncing ball for a game that I am making. Thanks

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: bouncing ball physics.

    There is no universal formula that describes how balls bounce. There are equations of motion, friction, spin etc.

    Be more specific.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: bouncing ball physics.

    Well atm I just have a ball falling in a 3D world and when it hits the ground I want to do something to simulate a bounce at the moment I have something like this and it works very badly.

    if ball.z < 0{
    zspeed(the updward motion)+=grav+zspeed
    }
    ball.z+=zspeed
    ball.z-=grav

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: bouncing ball physics.

    It all depends on how complex your game is, eg how 'life-like' it simulates the ball.

    The easiest example of a bouncing ball is probably by using the projectile motion equations. I will try to explain it a bit using a 2D-world but it translates quite similar to 3D I think.

    Basically, you give the ball a horizontal speed vx and a vertical speed of vy = 0 (you release it from rest) (for example, you could do it differently).

    Then, the horizontal, x, component of the speed will NOT change (unless it bounces against a vertical surface like a wall).
    The vertical, y, component of the speed will be constantly changing due to gravity.

    Basically, the y component is given by:
    vy = 0 + 1/2 g t2

    Here, g is the acceleration of gravity (9.8 m/s[sup2[/sup]) and t is the time.

    This is just for a free-falling ball.

    As soon as the ball hits the ground, it has a certain vertical speed and this vertical speed is then 'mirrored'. The equation then becomes:
    vy = - vbounce - 1/2 g t2
    Here, vbounce is the ball's speed at the time of the bounce (note that this speed will be negative, hence the negative sign to make it positive (up) again).


    If your game is more complex you must take into account the spin of the ball. Assuming that it is moving horizontally (not just bouncing on a certain position) then each time it hits the ground, the friction with the ground will cause it to spin. When it is spinning and it hits the ground, it is given a certain 'punch' (impulse) in the other direction. (For example take a ball and drop it on the floor while spinning rapidly. You will see that it bounces off in a certain direction instead of just up). This is all much more complicated though and I don't think this is what you want, right?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: bouncing ball physics.

    Alright I half understood that. Here is what I am doing now. It is not really working so ye.

    when the ball hits the ground this is what I am doing
    firstly I declare the variables

    time=0;
    zspeed=0;(updward force)

    while on_floor=0
    grav+=0.7(my gravity the downward force

    alright
    while z>ground
    time+=1

    and then on the bounce event here is what I am doing

    when it hits the ground
    (the speed at the time)zspeed=-grav-zspeed-1/2*grav*time.

    Now this mucks up pretty bad it just flickers on the ground. So can you point out what is wrong

  6. #6
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: bouncing ball physics.

    Sounds like you're re-applying downward speed directly after the bouncing, so it starts moving upwards and you immediately tell it to start going down again.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width