programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Physics

Sean Panting
Greenhorn
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
Greenhorn
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: http://www.marek-knows.com/downloads.php5?vmk=physics5a 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!

Mike Simmons
Ranch Hand
Posts: 3090
14
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.