Wednesday, January 09, 2008

Actionscript 2D Physics Engines Reviewed

For a while now I've been keen to get up to speed on the available 2D Physics Emgines for Actionscript. On New Years Eve Polygon Labs released a new Actionscript 2D Physics Engine : Motor2. Like Box2DFlashAS3 Motor2 is based on Erin Catto's c++ physics library Box2D. This release means there are now five Actionscript 2D Physics Engines available :

Henry Jones has posted a brief overview of all the engines, except Motor2, over on his blog. The release of Motor2 provides a good opportunity to bite the bullet and have a closer look at the available engines.

Methodology

To learn and test each engine I decided to build three simulations :

Hello World
This is a very simple simulation involving dropping a "ball" onto a sloping ramp. It essential is the most minimal simulation you can imagine. You need to create two types of shape (a circle and a rectangle), one fixed and one dynamic and you need to rotate one of the shapes. The objective here is to learn the fundamental mechanics of the engine.
Rope Bridge
The Rope Bridge simulation involves tying together a sequence of "planks" so they don't fall. Two of the engines have rope bridges in their demo application providing examples of best practices for building the bridge. The objective is to get an understanding of the basic constraint options for each engine. As with Hello World a ball is dropped onto the bridge to see how it reacts to a force.
Stunt Bike
The final test involves making a more complex object and running it down a ramp. The stunt bike has two wheels. The front wheel is connected to a steering column. In turn the steering column is connected at two points to the bikes body. The bikes body is connected to the back wheel. The objective here is to explore each engines constraint system in more detail.

You'll note that I'm not considering any benchmarking at this stage. This may seem odd as any simulation will live or die based on it's speed (and accuracy). I'm sure I'll be thinking in terms of benchmarking in the future. But for now my primary interest is what can each system do and how easy is it to do it. On the surface we might be forgiven for expecting a 2D Physics Engine to have a consistent set of features but that is definitely not the case here. Each of these engines has quite different objectives and therefore quite a distinct feature set.

Also note that I won't be testing either Motor2 or The Fisix Engine. For this review I'm interested in open source alternatives and Fisix is only free for non-commercial use. I haven't created any simulations using Motor2. At the moment the available demo's are too simple for my needs and there isn't any documentation to speak of. I will make some observations about Motor2. They will essentailly be what you might learn from staring at the engines code until it starts to make sense.

I will create seperate post for each engine I review. This will keep each post brief and easy to find. I will use this post to provide links to each review in the series.

5 comments:

Anonymous said...

I'll be interested in the outcome. Might help me decide how to implement the API for my engine.

http://yaa-blog.blogspot.com/

Andrew Garrahan said...

You rock thanks a lot!

Anonymous said...

Wow.. thanks for the reviews Geek Glue, very informative XD

I think you missed one, Glaze. It's based on chipmunk (not box2d as I thought it was in the FGL forums). Looking forward ^^

geekglue said...

I did take a look at Glaze when it was pEngine but it was a bit immature at that stage. There were actually a few Physics engines I didn't review for that reason. I might have to find some time to take another look. If anyone else is interested you can find out more about Glaze at :

http://yaa-blog.blogspot.com/search/label/Glaze

Anonymous said...

APE (Actionscript Physics Engine) is a free AS3 open source 2D physics engine for use in Flash and Flex, released under the MIT License. APE is written and maintained by Alec Cove. I am a college sophomore with a dual major in Physics and Mathematics @ University of California, Santa Barbara. By the way, i came across these excellent physics flash cards. Its also a great initiative by the FunnelBrain team. Amazing!!