🦀 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.
🌎 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.
- Joona Aalto talk at Bevy Game Dev Meetup The State of Physics in Bevy
- Johan Helsing Bevy Physics Engine Tutorial this tutorial is thoughtfully developed with excellent explanations of decisions made. It is based on an older version of Bevy, and you will need a little work to have to work with the latest Bevy version.
- 10 Minute Physics General Introduction to Game Physics by Matthias Müller, a Researcher at NVIDIA. The series has JavaScript demos, which you can run in a web browser. There is a gentle introduction to Extended Position-Based Dynamic (XPBD) in the Getting Ready to Simulate the world with XPBD (Simple and Powerful Simulations with XPBD) video.
- Research paper on XPBD , from NVIDIA.
Rust Physics Engine Libraries #
Here, we look at game development physics engines for use with Rust. In this section:
🎮 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 #
- GitHub repo: Jondolf/bevy_xpbd
- Rust crates: bevy_xpbd_2d & bevy_xpbd_3d
- Code examples: Bevy XPBD 2D Examples , Bevy XPBD 3D Examples
🎮 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 #
- GitHub repo: EmbarkStudios/physx-rs
- Rust crate physx
- Code example: physx ball physics example
- NVIDIA PhysX GitHub repo: NVIDIA-Omniverse/PhysX
🎮 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:
- GitHub repo: dimforge/rapier
- Rust crates rapier2d , rapier2d_f64 , rapier3d & rapier3d_f64 .
- User Guide: Rapier User Guide
- Getting Started: Getting started with Rapier Rust
- Code examples: see examples2d, examples3d-f64 and examples3d directories
🎮 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 #
- GitHub repo: dimforge/salva
- Rust crates salva2d & salva3d .
- Documentation: Salva docs
- Code examples: 2D examples 3D examples
🎮 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:
- GitHub repo: Bastacyclop/rust_box2d
- Rust crate wrapped2d .
- Code examples: Wrapped2D examples
- Box2D site: box2d.org
- Box2D GitHub repo: erincatto/box2d
🗳 Poll #
🙌🏽 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.
Just dropped blog post running though the Rust physics engine choices ranging from XPBD solvers to impulse, and velocity based ones, fully featured to a specialized fluid library.
— Rodney (@askRodney) March 13, 2024
Hope you find it useful!
#askRodney #learnRust #gamedevhttps://t.co/r4YU63SpHu
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.