File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Game Development and the fly likes Physics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Physics" Watch "Physics" New topic


Sean Panting

Joined: Oct 13, 2010
Posts: 3
Hello... im trying to make a game for my java programming class at school because of an assignment... anyways... its a game where you have to get the bouncing ball thru a hole in the wall, something like pong. well, ive got it all pretty much figured out... the problem im having is the physics on the ball. i did research on this already, and after some testing, created a class Ball that worked well for my other bouncy ball related game, but not this one. here's the code for class ball:

this actually works kinda fine. the ball actually works like a real ball... it starts going sideways, then goes more downward, and bounces off the bottom of the screen, and basically does an arc. it works, except the fact that each successive bounce is the same height as the one before. and there are probably other flaws to. but it still kinda works, for my needs. but its not random enough. the path of the ball is the same, it iterates 3 different paths, then starts over. i need the ball to be much more random. just for clarification, it follows the same arc every time, and the drop angle, thats the same every time, is wats causing the ball to not go thru the hole in the wall. if somebody could help me out, that would be great, thanks.
Marek Krzeminski

Joined: Mar 13, 2011
Posts: 14

If your ball keeps going to the same height with each bounce then there must be a problem with your friction calculation, or the friction is too low.

Have a look here: and compare the equations that I derive with what you have implemented.

For added randomness, each time the ball hits something, use a random number generator to "slightly" deviate the direction which the ball should go in so that the motion is more random!

3D OpenGL, C++ Game Development Video Tutorials @
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
It looks like your friction is always pointed in the same direction: -x and -y. Upward and to the left, I guess. So the ball slows down when it's falling downwards, but speeds up when it's moving upwards. You need the friction to change direction to always be opposite the direction of motion.
I agree. Here's the link:
subject: Physics
It's not a secret anymore!