Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Physics

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 14
C++ Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Master Rancher
Posts: 4966
78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic