Crates.io | bevy_xpbd_2d |
lib.rs | bevy_xpbd_2d |
version | 0.5.0 |
source | src |
created_at | 2023-06-19 17:16:47.316799 |
updated_at | 2024-07-04 17:12:06.394214 |
description | Deprecated, use `avian2d` instead. A physics engine based on Extended Position Based Dynamics for the Bevy game engine |
homepage | |
repository | https://github.com/Jondolf/bevy_xpbd |
max_upload_size | |
id | 894261 |
size | 994,611 |
⚠️ Bevy XPBD has been deprecated in favor of its successor Avian. No further development or maintenance will be done for Bevy XPBD. See #346 for background.
Bevy XPBD is a 2D and 3D physics engine based on Extended Position Based Dynamics (XPBD) for the Bevy game engine.
Below are some of the core design principles used in Bevy XPBD.
Below are some of the current features of Bevy XPBD.
SpatialQuery
system parameterf32
/f64
precision (f32
by default)You can find a more complete list along with documentation in the Table of contents on docs.rs.
First, add bevy_xpbd_2d
or bevy_xpbd_3d
to your dependencies in Cargo.toml
:
# For 2D applications:
[dependencies]
bevy_xpbd_2d = "0.5"
# For 3D applications:
[dependencies]
bevy_xpbd_3d = "0.5"
# If you want to use the most up-to-date version, you can follow the main branch:
[dependencies]
bevy_xpbd_3d = { git = "https://github.com/Jondolf/bevy_xpbd", branch = "main" }
Below is a very simple example where a box with initial angular velocity falls onto a plane. This is a modified version of Bevy's 3d_scene example.
use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, PhysicsPlugins::default()))
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Plane
commands.spawn((
RigidBody::Static,
Collider::cuboid(8.0, 0.002, 8.0),
PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(8.0, 8.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
},
));
// Cube
commands.spawn((
RigidBody::Dynamic,
AngularVelocity(Vec3::new(2.5, 3.4, 1.6)),
Collider::cuboid(1.0, 1.0, 1.0),
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 4.0, 0.0),
..default()
},
));
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 2_000_000.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-4.0, 6.5, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
You can find lots of 2D and 3D examples in /crates/bevy_xpbd_2d/examples and /crates/bevy_xpbd_3d/examples respectively.
The examples support both f32
and f64
precisions, so the code contains some feature-dependent types like Scalar
and Vector
.
In actual usage these are not needed, so you can just use f32
or f64
types depending on the features you have chosen.
By default the examples use f32
. To run the f64
versions, you need to disable default features and manually choose the dimension
and precision:
# Manually specify dimension and precision. `parry-f64` enables collision detection using Parry.
cargo run --example cubes --no-default-features --features "3d f64 parry-f64"
Note: Bevy XPBD is deprecated and won't support future versions of Bevy. Instead, it is recommended to use its successor Avian.
Bevy | Bevy XPBD |
---|---|
0.14 | 0.5 |
0.13 | 0.4 |
0.12 | 0.3 |
0.11 | 0.2 |
0.10 | 0.1 |
If you encounter any problems, feel free to open issues or create pull requests. For larger changes and additions, it's better to open an issue or ask me for input before making a pull request.
You can also ask for help or ask questions on the Bevy Discord
server's bevy_xpbd
thread in #crate-help
. My username on the Discord is Jondolf
(@jondolfdev
).
Huge thanks to the entire Bevy community for the incredible support! All of your contributions, insight and requests are a massive help in driving the state of physics in Bevy forward, and it's what keeps me motivated to build the best engine I can.
I would also like to give a special thanks to Johan Helsing
for inspiring this project and helping me significantly in the early stages.
His original tutorial series is the reason bevy_xpbd
exists in the first place, and without his support and contributions,
the project wouldn't be anywhere near where it is today.
Bevy XPBD is free and open source. All code in this repository is dual-licensed under either:
at your option.