Defold Crowd Native Extension

Collision avoidance is a subject I try to tackle from time to time. I have tried steering behaviors and custom solutions before. They all had their own pros and cons. Testing ORCA and RVO2 was always on my mind. Thanks to a push from @Alex_8BitSkull , I tumbled down the rabbit hole and somehow managed to come back :slight_smile:

I used RVO2 as a blueprint, but this solution was written from scratch. The only part I use is the ORCA solver, which is obviously based on the same algorithm.

There will be two versions available:

  • Standard is free for personal, educational, experimental, and completely free, non monetized games or apps. The Standard version is coming in autumn 2026.
  • Pro is available through paid access and requires at least a one time payment of $10 USD via GitHub Sponsors.

The Pro version is already available to all my past and current GitHub sponsors who have contributed at least $10. Special thanks for their support: @Alex_8BitSkull, @Pawel , Defold (team) and Refold (team), @AGulev

If you wanna check out the pro version → GitHub Sponsors

So… what is this?

Defold Crowd is a native extension for local crowd avoidance in Defold. It helps many circular agents move through the same 2D space while avoiding each other and static obstacles.

You provide positions, radii, speeds, neighbor settings, and desired velocity. The extension computes avoidance velocities and updated positions for the next simulation step.

What is it not?

Defold Crowd is not a complete movement AI system.

  • No pathfinding. Plug in your own A*, navmesh, waypoint graph, flow field, or route planner.
  • No formations or group movement. Squads, offsets, ranks, selection logic, and coordinated movement belong in your game code.
  • No universal arrival solution. Stopping, slowing down, snapping, attacking, queueing… They differ from game to game.
  • No physical collision solver. ORCA computes avoidance velocities, but your game may still need placement rules or overlap correction.

Extra features

  • Polygonal and circular obstacles. Circular obstacles are cheaper than vertex based obstacles.
  • Navigation masks. Air units do not collide with ground units, etc.
  • Avoidance responsibility. Selected units yield more, or vice versa.
  • Defold’s JobSystem and parallel simulation (Pro version only)

Managed game objects

There is a managed game object solution, but it is basically a reference implementation, not a production system. The managed game object API demonstrates how the native side drives Defold transforms, including goals, preferred velocity, simulation steps, and position write back.

It intentionally covers only the simplest case: a single collection of agents moving toward fixed world space goals. It can be treated as a starting point and a code reference. For real projects, you will probably want to extend it or replace it with your own native C/C++ implementation.

Technical features

The extension allocates during context setup and destruction; simulation steps use the memory reserved by the context.

  • No C++ STL containers or strings.
  • No classes; the core uses struct and namespace.
  • No virtual functions.
  • No exceptions or RTTI used by the source.
  • No runtime allocation during simulation. Memory is reserved at context creation and released at destruction.
  • Uses Defold allocation through dmMemory::AlignedMalloc / dmMemory::AlignedFree.
  • Explicit types only; no auto.
  • Small C/C++ standard headers only + Defold SDK headers.
  • Error handling uses result enums instead of exceptions.
  • Cache-conscious structs with DM_ALIGNED(N): Agent is 64-byte aligned, Obstacle is 32-byte aligned.

License Summary (not legally binding)

  • :white_check_mark: Standard is free for personal, educational, experimental, and completely free non-monetized games or apps.
  • :heavy_dollar_sign: Pro is paid-access only and requires at least a one-time payment of $10 USD via GitHub Sponsors.
  • :heavy_dollar_sign: Any monetized game/app using either version requires at least a one-time payment of $10 USD via GitHub Sponsors.
  • :envelope_with_arrow: Free releases are welcome to share project info (name, genre, date, links).
  • :locked: The Software is closed-source; source access may be granted upon request.

See License

21 Likes

Congratulations on the release! That looks amazing, great job

3 Likes

Thank you for sharing! This is awesome! :heart_eyes:

3 Likes

Thanks so much for your hard work! I am so excited to play with this in my next project :star_struck:

3 Likes

Thank you, @Insality and @Pawel. I really appreciate it!

Ah! So the next hit is coming then :slight_smile:

3 Likes

This is really, really cool. I’m imagining this is mainly for objects “on tracks”? So things like side on 2D objects with gravity, or cars with inertia, wouldn’t work easily?

1 Like

Thank you.
Nope, not really, unless you use pathfinding, probably HPA* and flow fields. I guess the logo might be misleading.

Sorry, I’m not sure I understand this correctly. But I can say that there is no gravity or force involved, only velocities.

This video probably explains it better:

3 Likes

The logo is great! When I said on tracks, I meant things that don’t slide or react physically.

Yeah exactly.

Sorry, I got over-excited and though this could potentially be used in a racing game with drift, or a platform game, but quickly tempered my excitement! :slight_smile:

Still super cool, it could work really well in a crowd simulation game.

1 Like

I hadn’t thought about this use case, but it seems very possible and could be very creative.

This could also be a very creative way to use it, if you’re willing to accept the challenges. It might become something like Swarm, but in 2D (XY or XZ).

2 Likes

This is amazing, congrats! Can’t wait to try it out when I get a chance!

2 Likes

Well done!
I can’t go into details but crowd sims are my daily job so for the sake of my sanity, I won’t look at this anytime soon :sweat_smile:

2 Likes

:flushed_face: this is absolutely not an industry standard(robotics etc.) or AAA game tool/solution (perhaps just Godot level) It is meant to be fun to use, so…

1 Like

Here is a video to see it in action!

https://x.com/i/status/2074045785201676402

1 Like

I intentionally didn’t share this or any other tests/statistics/benchmarks. People love to see this kind of stuff with large numbers, but in reality, games have so many other things going on that those numbers are not realistic at all. You need many layers of complexity on top of everything.

I would suggest that everyone look closely at the profiler and make their decisions accordingly, rather than relying only on FPS.

I benchmark every step and every part of the solution, checking how many milliseconds each calculation takes and comparing it with RVO2. The final version is 1.5 times faster than the original RVO2 implementation. That is all I can say. The rest is pointless. You should run your own tests based on your target hardware.

Since you already shared it, here is the original one :slight_smile:

You can push it to the limits for stress testing :slight_smile:

https://x.com/selimanac/status/2068396098394239387

6 Likes

I am here just for the music