Sign in to follow this  
ElectroDruid

Good free 2d physic engine?

Recommended Posts

Hi, I'm looking for the best free physics engine which would be suitable for use in a 2D game. I'm working in C/C++, and plan on building most of the rest of the game myself. I searched the forums and found a few threads on this, but they all seem to date back a few years, and I know that the state of play can change for engines, in terms of maintenance, support, documentation and stuff. I've written some horrible amateurish physics stuff based on Euler before. I've built a 2D Verlet physics engine, based on the Thomas Jakobsen stuff. It was nice and stable, and did cool stuff like cloth and rope physics, as well as rigid body stuff (and squishy stuff if I lowered the number of iterations), but I didn't have the collision detection skills to really polish it properly, and I think that would take a lot of time (I'll be honest, I've been writing games for a long time, but collision detection/response and physics don't come naturally to me). I tried using another Verlet-ish thing which I found here: http://ofbg.tripod.com/dolphin.html . The code is nice and straightforward, but really fell apart in terms of stability the moment I tried to push it a little bit. To keep this a little bit more focused than the standard open "which physics engine is best?", I'll try to list some of what I'm looking for, in rough order of preference, to try to narrow things down a bit. 1 - Something free. By which I mean, I don't want to have to pay a license if I want to make my game commercial. 2 - Something as free of bugs and as stable as possible. The less time I have to spend working out why my pile of 100 (or whatever) objects suddenly starts doing weird things, the better. Ideally I'd like something completely deterministic as well, but I know that's not an easy thing for a physics engine to do. 3 - Something that is still maintained, and well-documented and supported. I don't know what (for example) Newton is like these days, but when I last looked at it a couple of years ago, I found plenty of bugs, but no useful documention or message boards to help out with them. Nobody seemed to be maintaining it. No good to me. 4 - Something lightweight and portable. Something with a nice simple API that doesn't require reams of code just to throw a few boxes about, and that I can build a game on in any way I see fit (I've seen physics engines that need DirectX to run, for instance... Seems crazy to me) 5 - Something open source. I'm not a fan of linking to libs when I can't see what's in them or how they were written. If I want to make changes or check stuff, I'd like to be able to see, edit, and compile actual code. If the code is clean and well commented, so much the better. 6 - Something well-suited to 2D. Either something designed to work in 2D from the ground up, or something which I can use and ignore the z-axis without a significant performance hit. For the game I'm looking for, I want to be able to throw around a decent number of (probably fairly basic in terms of shape) 2D rigid bodies, have some stuff in there that can do rope and cloth physics (so, something with constraints which are reasonably easy to set up), a good amount of control over bounciness, friction, "squishiness", etc. If the engine can cope with fluid particle stuff to do liquids and gases, that would be marvellous too. Heh, sorry, this got a bit long. I don't mean to sound too picky, I'd just like to narrow my search down to some tried-and-tested solid engines rather than to just get a list of all the physics engines that are out there.

Share this post


Link to post
Share on other sites
You might want to check out the Box2D physics engine. I have heard good things about, although I have never used it. It fits most of your criteria. Here is the link to the features of it:
http://www.box2d.org/features.html

If you are willing to switch over to C# and XNA, then you can use Farseer. I have used this for a game I made for school. It is really simple, clean and quite stable (I don't think it supports rope physics, but you can probably simulate it by creating a bunch of primiatives and connect them together).
http://www.codeplex.com/FarseerPhysics

Share this post


Link to post
Share on other sites
I'm playing around with Box2D now. Not had a chance to poke around the code much, but I've played with the testbed, read the manual and seen some of the stuff that's been made using it, and so far at least I'm very impressed. Thanks for the advice! :)

Share this post


Link to post
Share on other sites
Quote:
Original post by pTymN
I've reviewed pretty much every serious 2d physics option out there, and Box2D is the best one, especially with continuous collision detection.


Tim, if I'm not mistaken, isn't your Chipmunk system based on Box2D?

Share this post


Link to post
Share on other sites
Yes, Chipmunk is based on Box2D and uses the same impulse-based constraint solver. I'm not sure whether or not it's more advanced than Box2D or not, but I think that it is more flexible and has support for more shape types, ropes, etc (don't quote me on this, I haven't kept up with either engine's development).

I also think that Chipmunk has a better broad-phase collision detection system. It uses a spatial hash, with theoretical O(1) performance with a high constant factor, while Box2D has O(n*log(n)) performance with it's sweep and prune method.

Actually, I just looked at Box2D and it seems to have progressed quite a bit since I last looked at it. The only thing I can see being an issue is that it uses C++, while Chipmunk has a C99 API. As much as I support Chipmunk, it seems like Box2D is probably the better choice here. It looks like it has more features and is under much more active development.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this