10 releases (5 breaking)
0.6.0 | Jul 7, 2024 |
---|---|
0.5.0 | Mar 3, 2024 |
0.4.1 | Mar 2, 2024 |
0.4.0 | Nov 17, 2023 |
0.1.0 | Mar 13, 2023 |
#59 in Game dev
180KB
3.5K
SLoC
Bevy plugin for PhysX 5
PhysX is an open-source Physics SDK written in C++ and developed by Nvidia.
This crate is a bridge between Bevy ECS and Rust bindings made by Embark Studios.
Getting started
Here is a snippet, which creates a ball bouncing on a fixed ground.
// this is similar to basic simulation example in rapier3d
use bevy::prelude::*;
use bevy_mod_physx::prelude::*;
use bevy_mod_physx::prelude::{Material, Shape}; // bevy prelude conflicts
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(PhysicsPlugins.set(
PhysicsCore::new().with_pvd()
))
.add_systems(Startup, setup_graphics)
.add_systems(Startup, setup_physics)
.insert_resource(DebugRenderSettings::enable())
.run();
}
fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-3.0, 3.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
fn setup_physics(
mut commands: Commands,
mut physics: ResMut<Physics>,
mut geometries: ResMut<Assets<Geometry>>,
mut materials: ResMut<Assets<Material>>,
) {
// Create the ground.
commands.spawn((
RigidBody::Static,
Shape {
geometry: geometries.add(Plane3d::default()),
material: materials.add(Material::new(&mut physics, 0.5, 0.5, 0.6)),
..default()
},
SpatialBundle::from_transform(Transform::from_xyz(0.0, -2.0, 0.0)),
));
// Create the bouncing ball.
commands.spawn((
RigidBody::Dynamic,
Shape {
geometry: geometries.add(Sphere::new(0.5)),
material: materials.add(Material::new(&mut physics, 0.5, 0.5, 0.6)),
..default()
},
SpatialBundle::from_transform(Transform::from_xyz(0.0, 4.0, 0.0)),
));
}
Compatibility / Prior art
published | 0.6.x | Bevy 0.14 | PhysX 5 |
0.5.x | Bevy 0.13 | PhysX 5 | |
0.4.x | Bevy 0.12 | PhysX 5 | |
0.2.x - 0.3.x | Bevy 0.11 | PhysX 5 | |
git tags | git:a21b570 | Bevy 0.11 | PhysX 4 |
(unpublished) | git:43ae89e | Bevy 0.10 | PhysX 5 |
git:8f66a99 | Bevy 0.10 | PhysX 4 | |
other crates | bevy_mod_physx v0.1.0 | Bevy 0.10 | deprecated |
bevy_prototype_physx | Bevy 0.2-0.5 | unknown | |
bevy_physx | never existed | ||
Note: you can find PhysX 4 version of this crate. It exists because PhysX 5 bindings don't have Vehicle API. It is not officially supported nor published to crates.io, and may get removed in the future.
Dependencies
~33–72MB
~1M SLoC