Box2D extension - open source now

I’ve made a Box2D extension, it’s currently small but very capable already.

To showcase the extension I am preparing a stream on YouTube soon.


I didn’t watch the video completely, but could you please describe what are the key benefits of using this extension instead of the built-in physics? As far as I know it also uses Box2D.

@astrochili I’ll make an overview video at some point. For now here is a brief list:

  • Direct API access. You are not limited by Defold’s collision object interface.
  • Full control of Dynamic and Kinematic bodies. In Defold it’s very hard to control them, for instance there is simply no way to set linear velocity or angular velocity for a body.
  • Multiple simultaneous worlds. You can have as many separate simulations as you want. In Defold there is only one.
  • Control over simulation speed. If you want you can calculate a simulation not in real time, but much faster. For instance it’s possible to simulate trajectory for a projectile over a course of several seconds in just one real-time frame. Not possible in Defold.
  • Virtual bodies. You don’t need visual representation of physics bodies with game objects like sprites. Useful for sensors or invisible walls.
  • Extensibility. The source code of the extension is available. If something is missing in the extension - you can write the code yourself to add it.
  • Latest version of Box2D.

In short, Defold provides an extremely limited access to Box2D functionality, making it very hard to make proper physics based games.


This sounds great. I think it could be especially useful when there will be a possibility to draw custom polygonal shapes. In that way, you’ll be able to make a lot of custom shapes in Tiled editor (a terrain for example) and import them to both Box2D world and some drawing processor. It would be powerful.

When will the library be available to try?

1 Like

At the moment my extension only supports rectangular and round shapes, but polygonal and multishape bodies will be available too at some point.

The extension is already available to my tier 2 patrons on Patreon. That is $5 a month.


Have you continued to work on this extension? Physics is Defold’s biggest remaining weakness to me, so I am very interested in this if it’s reasonably well supported.
Is it limited to certain platforms, or does it work everywhere?

Features that I would want (that I didn’t notice in the video):
(roughly of in order of priority)

  • Polygon and Chain shapes.
  • “Bullet” bodies.
  • Get body moment of inertia (needed for controlled rotation with torque).
  • Contact properties in callbacks: particularly the normal.
  • Ignoring collisions in PreSolve.
  • Dynamic attaching and destruction of fixtures from a body.
  • Raycasts.
  • “Sensor” fixtures.

Nice to have:

  • Set fixture density.
  • Get center of mass.
  • Joints.
  • Setting fixture categories & masks.
  • Pretty much everything else that Box2D has… :smile:

This is the one feature I miss most in Defold. Having it would open up a world of possibilities! Oh that and the one frame tunneling issue.


Related to this: @JCash is working on a component SDK which will allow us to break out components into separate repos. This will not only make community contributions easier but it would also allow the community to plug in their own physics engine and get the physics data created in the editor as input.

Our two main cases for this work is obviously to break out Physics and Spine from the engine.


There are plans to extend the extension, yes! Bullets, sensors are there. Getting properties is easy to add.
Joints are there, but can’t be modified yet.
Multifixture bodies are a bit harder.


Would be possible to tie this to the Defold collision shapes? It really does save a lot of time to be able to define collision boxes within Defold, instead of a third party software, like RUBE.

Wow. This is incredible news. This sounds like the kind of thing that might be a godsend for library authors in terms of making their APIs friendlier to end users.




Missed that, brilliant!

I’ve made the extension Open Source with no requirement to support and no fees. You are still welcome to support.

Grab it here