diff --git a/bevy_rapier2d/examples/player_movement2.rs b/bevy_rapier2d/examples/player_movement2.rs index 99e01f0e..e6e21df1 100644 --- a/bevy_rapier2d/examples/player_movement2.rs +++ b/bevy_rapier2d/examples/player_movement2.rs @@ -24,9 +24,13 @@ fn main() { #[derive(Component)] pub struct Player(f32); -pub fn spawn_player(mut commands: Commands, mut rapier_config: ResMut) { +pub fn spawn_player(mut commands: Commands, mut rapier_context: ResMut) { // Set gravity to 0.0 and spawn camera. - rapier_config.gravity = Vec2::ZERO; + rapier_context + .get_world_mut(DEFAULT_WORLD_ID) + .expect("Default world should exist") + .set_gravity(Vec2::ZERO); + commands.spawn(Camera2dBundle::default()); let sprite_size = 100.0; diff --git a/bevy_rapier2d/examples/testbed2.rs b/bevy_rapier2d/examples/testbed2.rs index e7a52a97..a81657b6 100644 --- a/bevy_rapier2d/examples/testbed2.rs +++ b/bevy_rapier2d/examples/testbed2.rs @@ -145,13 +145,12 @@ fn main() { ) .add_systems( OnExit(Examples::PlayerMovement2), - ( - cleanup, - |mut rapier_config: ResMut, ctxt: Res| { - rapier_config.gravity = - RapierConfiguration::new(ctxt.integration_parameters.length_unit).gravity; - }, - ), + (cleanup, |mut rapier_context: ResMut| { + rapier_context + .get_world_mut(DEFAULT_WORLD_ID) + .expect("Default world should exist") + .set_gravity(Vect::Y * -9.81) + }), ) // //testbed diff --git a/bevy_rapier3d/examples/change_world3.rs b/bevy_rapier3d/examples/change_world3.rs new file mode 100644 index 00000000..011549a7 --- /dev/null +++ b/bevy_rapier3d/examples/change_world3.rs @@ -0,0 +1,103 @@ +use bevy::prelude::*; +use bevy_rapier3d::prelude::*; + +const N_WORLDS: usize = 5; +const WORLD_CHANGE_DELAY_SEC: f32 = 3.0; + +#[derive(Component)] +/// Denotes which object(s) to change the world of +struct ChangeWorld; + +fn main() { + App::new() + .insert_resource(ClearColor(Color::rgb( + 0xF9 as f32 / 255.0, + 0xF9 as f32 / 255.0, + 0xFF as f32 / 255.0, + ))) + .add_plugins(( + DefaultPlugins, + RapierPhysicsPlugin::::default(), + RapierDebugRenderPlugin::default(), + )) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, change_world) + .run(); +} + +fn change_world(mut query: Query<&mut PhysicsWorld, With>, time: Res