Skip to content

🤺 Rapier 3D physics in Godot game engine

License

Notifications You must be signed in to change notification settings

deltasiege/godot-rapier-3d

Repository files navigation

Godot Rapier 3D 🤺

What is this?

A GDExtension that enables the Rapier physics engine within Godot.

It is not a drop-in replacement for the Godot physics engine. Rapier nodes operate separately from Godot physics.

Features

  • Cross platform determinism ✔️
  • Physics state manual stepping ✔️
  • Physics state saving & loading ✔️

Requirements

  • Godot 4.2.2 or later

Quickstart

  1. Download the latest --all release
  2. Extract the release archive into your godot project's root directory
  3. Add RapierRigidBody3D nodes to your scene and some RapierCollider3D + MeshInstance3D nodes as children of the rigid bodies
  4. Run your game

Your physics objects should simulate! 🎉

Configuring

By default, the Rapier3DDebugger autoload will start the physics simulation for you. To get more control over when you simulate, search for Rapier 3D in your project settings and disable either Debug in Game or Show UI under the Debug category.

Now you can call Rapier3D.step() from within any _physics_process() function, or as often as you like. This function advances the physics simulation by 1 step.

func _physics_process(_delta):
  Rapier3D.step()

Saving and loading state

Call Rapier3D.get_state() anywhere in your code to get a PackedByteArray representing the current physics state.

Use Rapier3D.set_state(snapshot) to set the physics state to a snapshot.

Obtain a hash of a snapshot using the Rapier3D.get_hash(snapshot) function.

var initial_snapshot

func _ready():
  initial_snapshot = Rapier3D.get_state()
  var hash = Rapier3D.get_hash(initial_snapshot)

func _on_button_pressed():
  Rapier3D.set_state(initial_snapshot)

Determinism

Confirmed via Github Actions across:

  • Windows, MacOS, Linux
  • arm64 / x86_64 architectures

Each release has a determinism-diffs.zip artifact that contains determinism test results

Roadmap

This extension is currently under heavy development, compatibility when upgrading versions is not assured until 1.0.0

  • Visualize colliders
  • Snapshots & stepping
  • Determinism automated testing
  • Collider shapes
  • Character controller
  • Sensors/Areas
  • Apply forces to rigidbodies
  • Visualize active vs inactive bodies
  • Collision layers
  • Save/load snapshots to/from resource files
  • Editor UI to facilitate simulating in editor
  • Gizmo handles for collider shapes
  • Add to Godot asset library

Why does this exist?

Currently Godot does not support on-demand physics simulation, does not have built-in snapshotting, and is also not deterministic.

These features are either important or required for creating networked games that use physics, depending on the chosen network architecture of your game.

Luckily, Godot 4 provides a great extension system and Rapier provides these missing features. 🚀

Limitations

Contributing

See CONTRIBUTING.md

Attributions