image

Phaser Studio is happy to announce the release of two new sets of templates and related tutorials that cover using the Rapier Physics library with Phaser 3.

Rapier is a fast, open source physics engine written in Rust. They provide a WASM build that allows you to use it directly from JavaScript. It's a feature-packed library offering rigid bodies, constraints, force-based joints (i.e. ragdolls, vehicles, robots, etc), contact events, scene queries and cross-platform determinism. It's a great choice for lots of types of games or multi-platform physics simulations.

Knowing that this would appeal to Phaser developers, we set about making it as easy to use as possible. This involved creating two brand new templates and 30 different source code examples.

Rapier Connector Template

The first template is the Rapier Connector. This plugin allows you to easily integrate the Rapier physics library with Phaser 3, making it simple to create and manage rigid bodies within a physical world in Phaser. It does this by providing a thin helper layer over the top of Rapier, organised around how Phaser itself works.

The template is available from the Rapier Connector GitHub repository. The README file in the repository includes instructions on getting started, example code and connector documentation.

You can find 15 different code examples of how to use the plugin in the Rapier Connector Phaser Sandbox

Examples

Native Rapier Template

The second template is the Rapier Phaser Template. This one offers a direct native integration of Rapier with Phaser. There is no plugin or layer over the top of it, so you're free to roll your own integration however you see fit. There's still lots of documentation in the README, and as with the Connector, we've created 15 different code samples showing the most common functions, including body creation, movement, collision response, chains and more. These are available in the Rapier Template Phaser Sandbox

Examples

Although Phaser includes two different physics engines by default (Arcade and Matter), it's always good to show alternatives. Rapier includes features that other open-source physics engines don't and being Rust and WASM based it has very good performance. That performance comes at a cost in the form of a hefty WASM bundle size (think 1.5MB added to your project), but for lots of games this is a worthy sacrifice to make, and these templates make it quick and easy to get up and running.

Rapier Physics with Phaser