Skip to content

Commit

Permalink
add example to output a debugdump of postupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Aug 8, 2024
1 parent c2bed72 commit 3324ff4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ approx = "0.5.1"
glam = { version = "0.27", features = ["approx"] }
bevy-inspector-egui = "0.25.1"
bevy_egui = "0.28.0"
bevy_mod_debugdump = "0.11"

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
Expand Down
61 changes: 61 additions & 0 deletions bevy_rapier2d/examples/debugdump2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
let mut app = App::new();
app.insert_resource(ClearColor(Color::srgb(
0xF9 as f32 / 255.0,
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0),
RapierDebugRenderPlugin::default(),
))
.add_systems(Startup, (setup_graphics, setup_physics))
.add_systems(PostUpdate, display_events);

bevy_mod_debugdump::print_schedule_graph(&mut app, PostUpdate);
}

pub fn setup_graphics(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

pub fn display_events(
mut collision_events: EventReader<CollisionEvent>,
mut contact_force_events: EventReader<ContactForceEvent>,
) {
for collision_event in collision_events.read() {
println!("Received collision event: {collision_event:?}");
}

for contact_force_event in contact_force_events.read() {
println!("Received contact force event: {contact_force_event:?}");
}
}

pub fn setup_physics(mut commands: Commands) {
/*
* Ground
*/
commands.spawn((
TransformBundle::from(Transform::from_xyz(0.0, -24.0, 0.0)),
Collider::cuboid(80.0, 20.0),
));

commands.spawn((
TransformBundle::from(Transform::from_xyz(0.0, 100.0, 0.0)),
Collider::cuboid(80.0, 30.0),
Sensor,
));

commands.spawn((
TransformBundle::from(Transform::from_xyz(0.0, 260.0, 0.0)),
RigidBody::Dynamic,
Collider::cuboid(10.0, 10.0),
ActiveEvents::COLLISION_EVENTS,
ContactForceEventThreshold(10.0),
));
}

0 comments on commit 3324ff4

Please sign in to comment.