DEV Community

Cover image for Rust Game Physics Engines: PhysX, Rapier, XPBD & Others
Rodney Lab
Rodney Lab

Posted on • Originally published at rodneylab.com

Rust Game Physics Engines: PhysX, Rapier, XPBD & Others

🦀 Rust Game Dev Physics Engines

Continuing the series, in this post, we see the choices for Rust game physics engines. As with an ECS and, to some extent, game engine, not every game will need a physics engine. We approach the post from the perspective that you have already decided you want a physics engine for your project, and are evaluating which physics engine might be a good fit for your game.

We focus on engines that are still maintained, and enjoy at least moderate use. Also, if you are curious about how physics engines work, we also see a tutorial, which you might follow to learn what is happening under the engine casing. If this is what you are looking for then let’s press on!

🤔 Rust Game Engine Choices

Bevy

Bevy has no official physics engine, though some of the physics engines we look at have Bevy-specific versions. Others were designed for use with Bevy, but work with other game engines. Bevy XPBD, for example, is designed for use with Bevy, though you can use it with other game engines, much like you can use the Bevy ECS with other game engines.

Other Game Engines

Some other Rust game engines ship with their own physics engine. Fyrox, for example, has advanced 2D/3D physics, supporting rigid bodies, joints, ray casting and more. Godot too, which has community-led Rust bindings also has an in-built physics engine as well as a Godot-native extension using the Jolt physics engine. In fact, which is reported to be more performant than the official physics engine.

Rust Game Physics Engines: screen capture shows a shower of squares in a 2D animation falling from an origin top and centre of the window.  The squares have uniform rotation and stack on a flat surface, below the source.

🌎 Resources for Learning more about Rust Game Dev Engines

Here are some of the resources I used to research this post. Hopefully you will find them useful for more background.

Rust Physics Engine Libraries

Here, we look at game development physics engines for use with Rust.

Rust Game Physics Engine: Bevy XPBD

2D & 3D XPBD-based physics engine written for Bevy

This engine was created by extending the Johan Helsing tutorial mentioned above. XPBD is a different approach to the impulse and velocity-based solvers used in other engines. XPBD can produce stable simulations, though the algorithm design can lead to issues modelling material that deform. The XPBD algorithm has substeps, with multiple iterations of the algorithm within a frame. This substep technique has been combined successfully with impulse-based solvers in other engines.

Bevy XPBD has a modular design, letting you swap out the default collision system for Signed Distance fields, for example.

Bevy XPBD will move away from the XPBD solver in coming months, which is worth bearing in mind if you are considering using it for your project.

Bevy XPBD Features

  • Collision detection using Parry;
  • constraints and joints;
  • ray casting and shape casting; and
  • a modular design.

Not currently included

At the time of writing, the following features have not yet been integrated: continuous collision detection (CCD), articulations (multi-body joints), soft bodies (cloth); and fluid simulation.

Learn more about Bevy XPBD here

🎮 Rust Game Physics Engine: physx

Rust binding for NVIDIA PhysX

PhysX is a mature physics engine used in Unreal Engine and Unity 3D, written in C++. Embark Studios originally wrote this Rust wrapper to bring the maturity (more than 20 years old) offered by PhysX to Rust games.

PhysX is fully featured and has been battle tested many times in released games over the years. Both PhysX and physx are open-source.

Learn more about physx here

🎮 Rust Game Physics Engine: rapier

2D and 3D physics engine for Rust

Rapier supercedes the earlier nphysics engine and is the most mature pure-Rust offering. It is fully cross-platform with web support. There are 2D, 3D and f32 and high precision f64 crates, which are all free and open-source.

rapier Features

  • Web platform support;
  • joint constraints; and
  • collisions and intersections.

For fluid simulation see Salva (below), also from the Dimforge organization, which couples with rapier.

Learn more about rapier here:

🎮 Rust Game Physics Engine: Salva

2D & 3D particle-based fluid simulation written in Rust

Salva offers 2D and 3D fluid simulation and has WASM support.

Salva Features

  • Multiphase fluids;
  • two-way coupling with Rapier; and
  • multiple models.

Learn more about Salva here

🎮 Rust Game Physics Engine: Wrapped2D

Rust binding for the Box2D library

The Box2D engine is the 2D physics engine used in Unity, and was also used in earlier versions of Godot. It is written in C++. Wrapped2D offers a Rust binding for Box2D.

Learn more about wrapped2d here:

🙌🏽 Rust Game Physics Engines: Wrapping Up

In this Rust game physics engines post, we got an introduction to Rust physics engine line-up. In particular, we saw:

  • an overview of the pure-Rust and C++ binding physics engines;
  • some key feature oof the engines; and
  • some resources for physics engine research.

I would love to hear from you, if you are also new to Rust game development. Do you have alternative resources you found useful? Is there a physics engine, or some detail that I missed?

🙏🏽 Rust Game Physics Engines: Feedback

If you have found this post useful, see links below for further related content on this site. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on X (previously Twitter) and also, join the #rodney Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Game Dev as well as Rust and C++ (among other topics). Also, subscribe to the newsletter to keep up-to-date with our latest projects.

Top comments (0)