What is the benefit of a physics library?

Hello

I still don’t understand why someone should use a physics library, (but in reality I haven’t tried to used one yet :persecutioncomplex:).

So, what are the big benefits of using a physics library over writing your own physics? What the library does for you that is hard to do?

I don’t have any problems doing linear algebra and to understand basic physics concept, the only thing I strive a little bit with is to detect the collision between object.

Should I use a physics library only for collision detection?

Physics are surprisingly hard to get absolutely right.

And often the mathematical solutions are too slow, so you’ll find yourself spending a lot of time cutting corners.

You’ll also have to build spatial subdivision algorithms, so you won’t have to check ‘everything against everything every frame’.

In the end, it’s just reinventing the wheel, and it saves you a lot of time if you can just download an existing library and get it going in a few hours, as opposed to months.

Then again, if you’re doing it for the learning experience and you can spare the time… by all means roll your own.

If your doing a basic game, that would only have the basics like gravity, then you can make your own. But if you want something like this: http://www.java-gaming.org/index.php/topic,20280.0.html then might be best if you use one.

Dynamics are easy.

Solving the O(N^2) every-body-vs-every-body collision check problem is a bit of work.

Writing collision detection routines for various shapes (for every pair of shape types that you want to use) is somewhat difficult.

Writing collision resolution routines for each shape pair is fairly hard. Making them work with fast bodies is extremely tough.

Once the whole damn thing is set up and you try it out, and your nice stack of five boxes starts to jitter and fall over of its own accord, you’re wanting to pull your hair out.

Once you finally figure it all out and you’re down to a few fps and three weeks of work is in the drain, you’d be wishing you’d just popped in a physics engine and spent the three or four days it would take to learn it. I speak from experience. :slight_smile:

Of course, this only really applies to games that need significant physics components; if you can get away without stable stacks or continuous collision detection, you can usually do much simpler things without too much trouble.