Box2D VS Nape

This is my short comparison between Box2D and Nape. I’ve used Box2D AS3, and then Box2D Alchemy for a year or so. I’ve spent a lot of time hacking through it, so I feel that I’m qualified to make this comparison. The thing you need to ask yourself is this: “Do I want more speed/performance, or do I want accuracy in my physics simulations?”

EDIT: Deltaluca has been helping me with my game, and I have been testing his new version of Nape, which is faster, stronger, better. He plans to tackle CCD, and has introduced island sleeping. The old sleeping will be implemented at some point in the future. The problems I was having with strange sleeping and other odd behaviors in Nape came from my use of a physics scale, something often used with Box2D. I can now say with confidence that Nape is the best choice for physics in Flash.

EDIT AGAIN: Deltaluca has been making a lot of progress on newnape (name pending?), and has added constraints and a lot of other things you should check out! The review below isn’t terribly outdated, but I’ll probably review both newnape and box2d after some more updates/milestones are completed.

If you want to stack a ton of physics bodies on top of each other with minimal slow-down, then Nape is your answer. Nape will allow you to have many physics bodies in your world/space with great performance. The sleeping system is a bit different than Box2D, and will allow objects to sleep individually, ignoring islands used in Box2D’s system. One side-effect that I’ve seen is that you can have a box fall asleep at a 45 degree angle, sitting on a corner point, but I’m sure some tweaks to the sleeping parameters could fix this. Using UniformSpace, instead of UniformSleepSpace have shown that its probably just the minimum sleep velocity or the minimum time before activating the sleep state. I simply haven’t dug deep enough into Nape yet to know exactly what parameter I need to change.

Nape Physics

Nape Physics

If you don’t need many physics bodies, or need fast moving bodies like bullets, Box2D is your answer. Nape doesn’t support continuous collision detection (CCD), or tunneling prevention. Essentially a high velocity body can pass through another body if it is thin enough. Object penetration seems like less of a problem in Box2D, and using the ‘isBullet’ parameter enables CCD, which will make sure objects can not pass through each other. Box2D wasn’t made for AS3, and the performance suffers. Nape was made with Flash in mind (yes its made in haxe), and is much more efficient than Box2D. I’ve also taken a look at a lot of other physics engines for Flash, like Motor2, physaxe or glaze, but Nape seems to beat them all in simulation speed.

Some hacks in Nape may solve some of the issues with tunneling. You could use some simple raycasts to check ahead or behind your object to see if it has passed through anything. I asked deltaluca (author of Nape) about CCD in FlashGameLicense chat, and he said it was something he’d like to implement. No ETA’s or anything, but it is an open source project. I’ll be using raycasts for my bullets using Nape, so I’ll get back to everybody when I see how well that works.

Nape Logo

Did I mention how cute the Nape logo is? Its CUUUTE!

Nape Forums (VERY HELPFUL!): http://deltaluca.me.uk/forum/index.php

Nape Project Page: http://code.google.com/p/nape/

Nape Documentation (ALSO VERY HELPFUL!): http://www.deltaluca.me.uk/doc/

If I’m wrong about anything, or this needs updating, you can always leave me a comment! I encourage it.

8 thoughts on “Box2D VS Nape

  1. Very good info! I’ve been using WCK my self, and then heard about Nape. I’ve been looking around for comparisons, and your post fit the bill. Has CCD been implemented in WCK yet?

    Also, I’ve heard people complain about the simulation quality of Nape, saying that Box2D has better simulation quality. Have you experienced this?

    Also, is it easy too create explosions with Nape? It took me a while to get a good explosion with Box2D Alchemy (WCK).

      • As far as simulation quality is concerned, I must note that the default iterations in Box2D is 10, which the default in Nape is 4. Changing this will obviously bump up the simulation quality. Honestly, both engines react in pretty much the same way. Another thing to note is that the mouse joint in Nape is highly over-powered in Nape, and can force bodies through each other. This is what people would probably interpret as lower simulation quality, but it’s just an extremely strong force, which can be modified to be more… normal.

        I know that CCD is on top of deltaluca’s list, but the other thing on top of his list are exams (he’s a student). He’s put Nape on hold until he’s finished with exams.

        “…unfortunately it is now time for me to start my nape-break and start revising for my exams so I will not be working on nape (though i probably still will a bit time to time) for the next month or so until my exams are over.” –deltaluca

        So we probably won’t see CCD until sometime in May, but he’s very open about development, and you can easily contact him on the Nape forums.

        http://deltaluca.me.uk/forum/index.php

  2. Pingback: Using the Nape v2.0+ Physics Engine in ActionScript 3 | Jean-Philippe Côté

  3. Pingback: Which Physics Engine for Flash and AIR apps? « Oh, by the way...

  4. Pingback: Using the Nape Physics Engine in ActionScript 3 | Jean-Philippe Côté

Leave a comment