A simple C++ module integrating the Box2D physics library into Godot Engine. Development is still in very early stages, everything is untested.
- Godot: https://godotengine.org
- Box2D: http://box2d.org
Godot Engine already contains a very good, albeit simple, 2D physics engine implementation that is more than enough for most games. However, 2D games that require a bit more control and flexibility over its physics could benefit from a bigger and more complex implementation.
- Integrates Box2D 3.1.2 into Godot as a C++ module.
- No setup required. If you can build Godot from source, you can use this module.
- Does not disable or replace Godot's 2D physics engine.
- Provides Object wrappers for every Box2D entity
- i.e.
b2World
becomesWorldB2
- i.e.
- Full access from C++ and GDScript
- Clone the contents of this repository into
<Your Godot source folder>/modules/box2d
- Please note that this project is meant to be used with Godot's 3.1 branch.
- Build and run Godot normally
This module attempts to mimick Box2D's API while remining faithful to Godot's naming standard. Remember that units are all in the KMS system.
Box2D API | GDScript |
---|---|
|
|
Instead of the Create
/Destroy
combo (i.e. CreateJoint
/DestroyJoint
), Godot's familiar instance()
/free()
functions are used.
Box2D API | GDScript |
---|---|
|
|
Same as Box2D's regular API, destroying a parent object automatically destroys its children.
Box2D API | GDScript |
---|---|
|
|
The singleton Box2D
provides functions for creating shapes and shortcuts for bodies and fixtures. (bypassing the need to create BodyDefB2
and FixtureDefB2
)
# Shapes
shape = Box2D.box(Vector2(1, 1))
shape = Box2D.circle(Vector2(), 0.5)
# Shortcuts
body = Box2D.body(world, BodyB2.STATIC)
fixture = Box2D.fixture(body, shape, density)
This is all the documentation I have for this module, since it's in very early stages. If you know Box2D's API well enough, looking into the headers should point you in the right direction.
Released under the MIT License.