Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Ball Physics in 2D  (Read 2482 times)
0 Members and 1 Guest are viewing this topic.
Offline Daz

Senior Newbie




Java games rock!


« Posted 2004-11-23 20:38:26 »

Hi, i have created a 2d snooker game, which implements collision detection, but i am not sure how to implement the physical simulation of the balls, i.e. the formulas needed to calculated the force, acceleration, FRICTION, etc.  At the moment the balls look like they are sliding along the table at a constant speed. I have looked at alot of stuff on the web about this, but have not found anything i understand, i am not very good at maths, so has anyone got any simple solutions or something which i'll understand?
 
Offline Curro

Junior Newbie




Java games rock!


« Reply #1 - Posted 2004-11-24 10:37:10 »

Here http://www.d6.com/users/checker/dynamics.htm you can find everything that you need.
Offline Daz

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-11-24 12:51:45 »

Is there anything easier to understand out there, i.e. is there anyone who can provide me with simple steps to caculating the friction, force, etc, which is easy for someone who finds it difficult to understand complex mechanics
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2004-11-25 08:29:31 »

No. It's just that complicated. You've to hammer it into your head as everyone else did Wink

弾幕 ☆ @mahonnaiseblog
Offline jherber

Junior Member




Java games rock!


« Reply #4 - Posted 2004-11-25 23:08:48 »

here is one way to do a math-lite simplified physics simulation:

try subtracting a constant amount from the velocity to add friction to your model.  this will get you a simulated effect for the dynamic component of friction.  for the static component of friction, you basically want to do the same thing, but make it apply only at the initial impact.  this is basically the effect you feel when you have to slide a big box on the floor.  it takes more force at first until the box breaks free, and then it slides much easier.

acceleration isn't worth dealing with if you want to skip math and do simple simulated phyics.

collisions... not sure what a snooker table looks like, but there are basically two types of collision - elastic and inelastic.  elastic collisions keep the energy of the collision in a kinetic form (rather than convert to heat).  for billiard balls, this is what you want.  you have to follow the conservation of momentum.  something like m*v of one particl must be equal to the m*v of the other particle.  since your billiard balls all have equal mass, you are really just passing the speed from one ball to another (assuming no spin).

now, the most difficult aspect of your game would be spin imparted by the cue.  you could always have a spin component that each time step affects the path of the ball, and it may also affect the ball after the collision.   the rate of spin generated will be directly proportional to the force of the cue impact and the distance away from the center of the back of the ball being struck.   so, if you want a little spin, you hit slightly off center, etc, etc.

each time step
   for all balls on table
        if (speed > STATIC_THRESHOLD)
           speed = speed - speed * COEFFICIENT_OF_FRICTION_DYNAMIC + spin
       else
           speed - speed - STATIC_THRESHOLD.

       if speed < 0, speed = 0

i'll leave the implementation of spin up to you, but it should  also take friction into account.  when i hit the ball hard and it spins real fast, that is dynamic friction.  when the ball falls below some threshold speed, it grabs and the static friction sets in.  

i haven't talked about direction at all, but your simple simulated physics can account for everything by just having a speedX and a speedY.  

Offline Daz

Senior Newbie




Java games rock!


« Reply #5 - Posted 2004-11-26 13:48:47 »

Cheers for your help, that is really useful.  But there is one more thing I am confused about, how do u know what angle the cue ball and the red ball will travel once they hit?

Thanks,

Daz
Offline Daz

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-11-26 13:52:21 »

also forgot, what do you actually mean by static threshold, what could this be set at?
Offline jherber

Junior Member




Java games rock!


« Reply #7 - Posted 2004-11-26 18:24:06 »

Quote
Cheers for your help, that is really useful.  But there is one more thing I am confused about, how do u know what angle the cue ball and the red ball will travel once they hit?


i'm assuming you have not had a trigonometry class.  that is the type of mathematics that would be helpful here.  

let's look at the simple case.  draw a cue ball.  now, draw two balls touching the cue ball (in front of it).  now draw a line that represents the direction of the cue (it's path).  draw this line to the center point of the que.  now, with the two balls touching the que ball, draw a line from the center of the que ball to the center of the other balls.  that last line should be the direction the second ball is going.

but, how fast will the balls be traveling now?  that will be tough to figure out without trig.   but, we can still cheat without involving trig :>   the clue is in the comparison of the angle made between the line of the cue's path, and the line from the center of the que ball to the center of the ball about to be struck.  between them is an angle.   in your diagram you may have noticed that the larger the angle (or if you have a straight line - 180 degrees) then you will have the maximum transfer of force from the que ball.  if you have a 90' angle, then you have a glancing blow, where the queue will retain most of the energy (speed) and impart a bit on the queue.  so, use your creativity to add some kind of ratio involving this angle into your calculation of how much force is given up by the que ball onto the the collision ball.  

i think you are approaching the limits of what can be done without knowledge of physics and trig.  if this interests you, trig is easy and fun.  you can probably get the physics information you need by skimming here and there without delving too deeply in the mathematics.
Offline jherber

Junior Member




Java games rock!


« Reply #8 - Posted 2004-11-26 18:30:05 »

Quote
also forgot, what do you actually mean by static threshold, what could this be set at?


static threshold is when the static friction no longer applies and thus we switch to dynamic.   as i discussed, when you are sliding a heavy box, and all of sudden, it because easy to slide, that is the tipping point upon which you have reached the static friction threshold.  you can google it and find all kinds of numbers for friction constants between surfaces.  but, since you are not really doing a true physics model, the value should just be hand tweaked.  after all, we are "hacking" physics.  try a small value and increment it up until the collision looks realistic.

and, hit a used book store and buy a cheap physics book that has lots of diagrams.   it will help you understand by allowing you to picture in your head of what is going on during these interactions.

best of luck,

jim
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (11 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!