Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (622) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Ball Physics in 2D  (Read 2794 times) 0 Members and 1 Guest are viewing this topic.
Daz

Senior Newbie

Java games rock!

 « Posted 2004-11-23 19: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?

Curro

Junior Newbie

Java games rock!

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

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

Senior Newbie

Java games rock!

 « Reply #2 - Posted 2004-11-24 11: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
oNyx

JGO Coder

Medals: 2

pixels! :x

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

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

jherber

Junior Devvie

Java games rock!

 « Reply #4 - Posted 2004-11-25 22: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.

Daz

Senior Newbie

Java games rock!

 « Reply #5 - Posted 2004-11-26 12: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
Daz

Senior Newbie

Java games rock!

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

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

Junior Devvie

Java games rock!

 « Reply #7 - Posted 2004-11-26 17: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.
jherber

Junior Devvie

Java games rock!

 « Reply #8 - Posted 2004-11-26 17: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.

 BurntPizza (26 views) 2015-04-23 03:42:11 theagentd (29 views) 2015-04-22 16:23:07 Riven (44 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (60 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 30x BurntPizza 16x wessles 15x 65K 11x Rayvolution 11x alwex 11x kingroka123 11x KevinWorkman 9x kevglass 8x phu004 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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