-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example to output a debugdump of postupdate
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
)); | ||
} |