12
\$\begingroup\$

I'm making a pool-game like game. This game requires correct (or very accurate) reflective bounces. I tried Box2D and Bullet Physics, but they both have this problem.

Illustration

If there is a wall on top of this image, red line is expected course of a real ball in a pool-game. But the engines often shows green line course. Especially,

  1. This happens after a slowly moving ball hits the wall.
  2. Sometimes a rapidly moving ball get slower suddenly.

I'm finding a physics engine which can simulate pool-game accurately as much as possible without these problems. Can I get some recommendations? Now I'm digging Newton Game Dynamics, but I am not sure the engine will show what I want. I'm considering the PhysX engine as a next trial, and have to make my own if nothing works. But it's obvious it'll take very long time, so I wish I won't do that. I'll be very appreciated if you save my time. And of course, solution with Box2D / Bullet Physics are also welcomed.

I am working with C/C++/Objective+C on iOS.


I attach my configuration with Box2D.

Walls

  • static box shape
  • linear/angular damping = 0.1
  • restitution = 1.0
  • friction = 100
  • density = 10
  • bullet = false
  • fixed rotation = false
  • inertial scale = 1.0

Balls

  • dynamic sphere shape
  • linear/angular damping = 0.1
  • restitution = 1.0
  • friction = 100
  • density = 20
  • bullet = true
  • fixed rotation = false
  • inertial scale = 1.0
\$\endgroup\$
  • 3
    \$\begingroup\$ chances are that the engine is not wrong, but you've not set a property or doing it wrong somehow. \$\endgroup\$ – The Communist Duck May 6 '11 at 16:37
  • \$\begingroup\$ possible duplicate of Is there an algorithm for a pool game? \$\endgroup\$ – bummzack May 7 '11 at 16:31
  • \$\begingroup\$ I tested with density 1 and friction 0.0 ~ 0.1, it keeps sticking. \$\endgroup\$ – Eonil May 10 '11 at 7:54
8
\$\begingroup\$

Several solutions.

  1. For Box2D, set b2_velocityThreshold in b2Settings.h file. In my case, I set it to 0.0f and it worked! Mass, friction, damping were NOT problem. Check this discussion thread for more details. http://www.box2d.org/forum/viewtopic.php?f=3&t=6906&p=30782#p30782

  2. Using other physics engine. Newton Game Dynamics configured performing this correctly by default. However using Newton dynamics in iOS is possible but it's somewhat harder than others. I used several days configuring it for iOS.

I'm also asking on BulletPhysics forums. I'll update this when I got a solution.

-- (edit) --

There are some threshold attributes in Bullet, however I couldn't find exactly same thing with b2_velocityThreshold.

This looks similar, but didn't work well.

btRigidBody->setContactProcessingThreshold(0.0f)
\$\endgroup\$
6
\$\begingroup\$

Box2D will do what you want but you have to set the restitution (bounce) constants for the wall and ball fixtures. For a pool game you probably want to start with perfect restitution and high friction but linear and angular damping, and tweak from there.

\$\endgroup\$
  • \$\begingroup\$ I tried many configurations over few days, but it still happens. Can I get one good example...? \$\endgroup\$ – Eonil May 7 '11 at 1:33
  • 3
    \$\begingroup\$ Your density and friction values seem very large, for Box2D. \$\endgroup\$ – user744 May 7 '11 at 9:56
4
\$\begingroup\$

Physics engines have a bounce threshold. I don't know how to do it in either of those engines, but the threshold being set too high will cause it to ignore impacts under a certain velocity. Lower the bounce threshold and it will bounce at lower speeds.

I know you asked for a different physics engine, but all physics engines I know of use bounce thresholds to keep objects from jittering when they're sitting on top of each other. So suggesting a good physics engine will be counterproductive as any good physics engine will have this effect.

\$\endgroup\$
0
\$\begingroup\$

I had this problem and for me the solution was providing perfect restitution.

So for me that is sqrt of 0.5 for all objects. Because sqrt(r1*r1 + r2*r2) == 1 in perfect situation.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.