×

Discussion Board

Results 1 to 9 of 9

Thread: Physics!!!

  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Red face Physics!!!

    Hi all,
    I would like to do some tests on the physics of bouncing balls. Can anyone point me to some good resources where to start to make the bouncing ball look realistic (including obstacles or other balls bouncing as well)?

    P.S. I am an amateur programmer and if I tell you what my real job is you'll actually going to laugh so don't ask

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

    Re: Physics!!!


  3. #3
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Physics!!!

    Thanks!
    Do you think the code found by google is enough or I need to read a bit more about object interactions when bouncing etc...?

    Looking into the example (quite a few of them) there is something usefull but I would like to simulate gravity and a sort of "reality" in the movements of the ball...let's say it drops from the top of the screen it would bounce higher then it would if it was dropping from half screen. As well as at every bounce it would get not at the same height as the previous bounce...and this sort of things

    P.S. I am a dentist
    Last edited by sandro1972; 2007-06-13 at 00:13.

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

    Re: Physics!!!

    The Google code is probably quite sufficient. You might wish to consider buying a book like this one: http://www.oreilly.com/catalog/physicsgame/index.html

    P.S. Cool. :) Programming is a fun hobby. May day-job is in software/system creation, so actual programming is just a hobby nowadays (and I was never good/productive enough to be really useful).

  5. #5
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Physics!!!

    I came up with a function but...
    The ball falls (bounce = false) then bounces (bounce = true). When it's coming up at half way up and almost at the top it trembles, so the motion is not fluid. What could the problem be? [in the emulator]

    On the phone works fine?????????????

    Why?
    Last edited by sandro1972; 2007-06-15 at 19:41.

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    Re: Physics!!!

    i think ur in the wrong Forum..

  7. #7
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Physics!!!

    Is it because I am a dentist or because functions for fluid movements of a ball in a game is not related to java game programming?

  8. #8
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

    Re: Physics!!!

    Oh, I think the discussion can continue here.

    Perhaps you could post your code, sandro1972, so that people can see it and possibly spot things that need fixing?

  9. #9
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Physics!!!

    Thanks,
    the code is OK. On the phone the movements of the ball are really fluid. I think I'll stick with my Nokia emulator and try it on the phone from time to time to see what's the real result...
    anyway...
    Code:
        private int calcY(){
            
     
            
            Yseconds = (System.currentTimeMillis()-this.startTime)/1000.00;
            
    
            if (!bounce){
                SPEED_Y = ACCELERATION*Yseconds;
                if (y>(this.getHeight()-this.ballSprite.getHeight())) {                
                    bounce=true;
                    this.startTime = System.currentTimeMillis();
                    B_SPEED_Y = SPEED_Y*0.80;
                }
                y =top + ((ACCELERATION/2)*(Yseconds*Yseconds));
            } else {
                //distance = initial velocity * time + acceleration * time^2 / 2
    
                y = bottom - (SPEED_Y*Yseconds) - ((ACCELERATION/2) * (Yseconds*Yseconds));
                SPEED_Y = B_SPEED_Y - ACCELERATION*Yseconds;
                //System.out.println(SPEED_Y+" "+Yseconds+" "+y);
                if (SPEED_Y<=0) {
                    bounce = false;
                    top=y;
                    this.startTime = System.currentTimeMillis();
                }
            }
           
            return (int)y;
        }

Posting Permissions

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