Community Challenge #6: Box2D scripting 📦

Hi!

It’s time for another Defold Community Challenge! This time we invite you to try Defold 1.13.0 beta and play with the new and improved Box2D scripting API! :gear:

:bullseye: Goal

Create a Defold project that uses Box2D scripting.

Last time we also had a physics related challenge, but this time it is all about controlling physics from Lua: querying the world, creating and modifying shapes, using joints, changing materials, casting rays or shapes, inspecting contacts, triggering explosions, building tools, debugging physics, or making small gameplay prototypes powered by the new b2d.* APIs.

Your entry should use Lua Box2D API to directly control, query, inspect, or modify the physics simulation. It does not need to be a complete game. A small toy, tool, prototype, puzzle, sandbox, editor, debug visualizer, or interactive demo is perfectly fine.

Examples of what you can build:

  • Small physics playground
  • Runtime terrain made from chain shapes (like in this example)
  • Springy bridge or hanging chain toy
  • Grappling hook with raycast + joint creation
  • Click-to-inspect physics objects
  • Explosions and destruction
  • Physics vehicle with wheel joints
  • Dynamic material playground: ice, rubber, mud, metal
  • Tiny level editor that creates physics geometry from points
  • Sensor/contact event visualizer
  • Shape-cast based controller

:brain: Learning Goals

The goal is to learn the new APIs, test them in real projects, and create useful open-source examples for the community.

  • Learn how to use the b2d.* scripting APIs in Defold.
  • Experiment with runtime access to bodies, shapes, joints, chains, and worlds.
  • Try raycasts, shape casts, overlaps, sensors, hit/contact events, explosions, and debug data.
  • Explore the differences between Box2D v2 and Box2D v3 where relevant.
  • Help test the new Defold 1.13.0 beta physics scripting features.
  • Share small, readable, open-source examples that others can learn from.

:gear: API overview

B2D API was vastly enhanced for 1.13.0:

Note, that there are significant differences between the old V2 legacy version and V3. You can mention in your submission which APIs you used and whether your project uses Box2D v2 or Box2D v3 (or supports both).

:stopwatch: Time

28 days

From: 2026-06-14T13:00:00Z2026-07-12T13:00:00Z
(with a grace period if needed for late entries)

:memo: Submission Requirements

Submit your entry in this thread with:

  • The title and a brief description
  • A playable build, preferably HTML5 or desktop
  • A link to a public GitHub/GitLab repository
  • Optional visuals: GIFs, screenshots, videos, debug views

Entries must:

  • Be built in Defold 1.13.0 beta (or stable, when it releases)
  • Use Defold’s built-in Box2D scripting APIs in an essential way
  • Be self-contained and open source

Community or your own extensions and assets are fine for visuals, UI, audio, tooling, or support code, but the physics scripting showcase itself should use Defold’s built-in b2d.* APIs.

:trophy: Rewards

Defold sponsors 3 awards for the challenge: €25 Steam Gift Cards!

The Defold Team will select winners in these categories:

  • :gear: Best Box2D API Showcase - the clearest and most interesting use of the new scripting APIs
  • :test_tube: Best Physics Experiment - the most fun, surprising, or creative interactive physics prototype
  • :hatching_chick: Best First-time Entry - the best entry by someone who did not participate in previous community challenges

We will announce and contact the winners after the challenge ends. It would help when you win, if you could provide us your Steam ID and sent defoldengine an invite on Steam :wink:

:light_bulb: Inspiration & Ideas

Past challenges:

The challenge is not about building the largest project. Small, clean, readable demos are very welcome, especially if they help other developers understand how the new API work.

Have fun, break things, and share what you discover! :rocket:

21 Likes

I love this challenge. Great idea!

2 Likes

Just fyi, the ‘Defold Physics examples’ link goes to a 404 page.

1 Like

Thanks, yeah, because of the dynamic filters there are no more links to sections in the examples :thinking:

Check out the examples for Box2D scripting:

6 Likes

**Box2D Mouse Joint | Defold

**
This feels amazing. Just moving them around the screen feels fun.

2 Likes

Hi, I tried to build this project GitHub - JCash/example-box2d: An example how to use Lua scripting with Box2d in Defold · GitHub because I wanted a Box2d v3 working…

But I have this error:

lld-link: error: could not open 'libscript_box2d.lib': No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

com.defold.extender.ExtenderException: java.io.IOException: windres -i /var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//lib/x86_64-win32/engine.rc -O coff -o build/dmengine.res
clang++ -DDLIB_LOG_DOMAIN="UNKNOWN" -DDDF_EXPOSE_DESCRIPTORS -DDM_PLATFORM_WINDOWS -D_CRT_SECURE_NO_WARNINGS -D_CRT_USE_BUILTIN_OFFSETOF -D_WINSOCK_DEPRECATED_NO_WARNINGS -D__STDC_LIMIT_MACROS -DWINVER=0x0600 -DWIN32 -DNOMINMAX -DDM_DEBUG -target x86_64-pc-win32-msvc -m64 -O2 -g -gcodeview -Wall -Werror=format -fvisibility=hidden -nostdinc++ -fno-exceptions -nostdinc++ -isystem /usr/lib/llvm-20/lib/clang/20/include -isystem /opt/platformsdk/Win32/MicrosoftVisualStudio2026/VC/Tools/MSVC/14.51.36231/include -isystem /opt/platformsdk/Win32/MicrosoftVisualStudio2026/VC/Tools/MSVC/14.51.36231/atlmfc/include -isystem /opt/platformsdk/Win32/WindowsKits/10/Include/10.0.28000.0/ucrt -isystem /opt/platformsdk/Win32/WindowsKits/10/Include/10.0.28000.0/winrt -isystem /opt/platformsdk/Win32/WindowsKits/10/Include/10.0.28000.0/um -isystem /opt/platformsdk/Win32/WindowsKits/10/Include/10.0.28000.0/shared -I/var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//include -I/var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//sdk/include -I/var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//ext/include build/main.cpp -c -o build/main_tmp0.o
clang++ -o build/dmengine.exe -target x86_64-pc-win32-msvc -m64 -O2 -g -fuse-ld=lld -Wl,/entry:mainCRTStartup -Wl,/safeseh:no -L/tmp/job13446997600449253002/build -lOpenGL32 -ldelayimp -lUser32 -lshell32 -lXinput9_1_0 -ldinput8 -ldxguid -lWS2_32 -liphlpapi -lDbgHelp -lAdvAPI32 -lbcrypt -lPsapi -lGdi32 -lole32 -llibphysics_2d.lib -llibbox2d.lib -llibscript_box2d.lib -L/var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//lib/x86_64-win32 -L/var/extender/sdk/5ee7401faa26e6d90385ecef7029fcd3db750520/defoldsdk//ext/lib/x86_64-win32 -L/opt/platformsdk/Win32/MicrosoftVisualStudio2026/VC/Tools/MSVC/14.51.36231/lib/x64 -L/opt/platformsdk/Win32/MicrosoftVisualStudio2026/VC/Tools/MSVC/14.51.36231/atlmfc/lib/x64 -L/opt/platformsdk/Win32/WindowsKits/10/Lib/10.0.28000.0/ucrt/x64 -L/opt/platformsdk/Win32/WindowsKits/10/Lib/10.0.28000.0/um/x64 -llibengine -llibengine_service -llibdmbedtls -llibzip -llibprofile -llibprofilerext -llibprofiler_remotery -llibrecord -llibgameobject -llibddf -llibfont -llibresource -lgamesys -lgamesys_model -lgamesys_rig -lscript_box2d_defold -llibgraphics -llibgraphics_transcoder_basisu -llibbasis_transcoder -lplatform -llibrender -llibrender_font_default -llibscript -llibluajit-5.1 -llibextension -lhid -linput -llibparticle -llibrig -llibdlib -llibimage -llibglfw3 -llibgui -llibcrashext -llibliveupdate -llibsound -lvpx -llibdecoder_wav -llibdecoder_ogg build/main_tmp0.o build/dmengine.res

My Defold version is
image

1 Like

When using beta, you need also to change the build server to build-stage. Open File → Preferences and in tab “Extensions” type:

https://build-stage.defold.com/

2 Likes

I reported this problem on the 1.13.0 beta page. Following your suggestion, I changed the build server to “https://build-stage.defold.com/” but it still produced the same error.

lld-link: error: could not open 'libscript_box2d.lib': No such file or directory
1 Like

Marbles in a bucket.

html5: Marbles into a bucket

github: alfowler1976/defold_chain_test

It generates a spline from a series of points, then uses it to create two Box2D chains forming a pipe. Since chain collisions are one-directional, I had reverse the array list on one of the chains to get the collisions working correctly. I initially hoped to make it more of a puzzle game but once the prototype was up and running, I realized it wasn’t really going anywhere past the concept.

7 Likes

Love it, a few more levels please :grinning_face_with_smiling_eyes: Also, this is a very clean and great example of using buffers. Thank you for sharing the source

3 Likes

Great example @Andrew_Fowler! :heart_eyes:

We’ve also added few more to the examples page:

10 Likes

Hi! A few methods in the beta docs mention b2d.body.create_shape, but the b2d.body page seems to be missing the definition for this method. Is this API already implemented and just undocumented? If so, where should I open the issue?

1 Like

Must be something wrong with the API, we’ll check tomorrow, it is in the alpha version API though:

1 Like

After gaining some confidence with the marbles example, I decided to try something a bit more complex. I thought about creating a hill-type game—a classic b2d chain game. Initially, I tried building the landscape in chunks, but that didn’t work because updating a mesh with set buffer changes all instances. So instead, I went with a treadmill approach, generating a landscape mesh just for the visible screen and updating it each frame, while keeping the b2d chains as chunks.

For the buggy, I set up two polygon collision shapes using b2d.body.create_shape, but the tricky part was dealing with Defold collision messages. Adding the shapes was enough for dynamic physics collisions to work, but they didn’t trigger any contact or trigger events. I fixed this by using b2d.shape.get_filter_data (learnt from the Defold 1.13.0 beta thread) to grab the collision data from the original collision element on the game object, then applied it to the new shapes with b2d.shape.set_filter_data. Trigger events also needed the function b2d.shape_sensor_events to work. I hit the same issue with b2d chains, since they wouldn’t send contact events when interacting with the wheels. For chains, the filter data has to be set for each segment individually.

I think this needs a bit more integration. There doesn’t seem to be a way to determine which Defold collision group corresponds to the masked_bits in the filter data. All I could do was copy and paste from the existing collision body and hoped it worked!

github: https://github.com/alfowler1976/buggy-climb

itch.io: https://afowleer77776.itch.io/buggy-climb

14 Likes

Only 9 days left! How are you going? :smiley:

New example showcasing queries and raycasts:

8 Likes

Wondering if we’re going to need a Box 3D challenge in the future? :smiley:

5 Likes