Sync rigid body positions with coordinates, and don't sync coordinates for physics objects with transforms

This commit is contained in:
Nolan Darilek 2021-06-02 15:50:12 -05:00
parent cc249ad4fb
commit 5a6a3efb35

View File

@ -487,7 +487,7 @@ fn setup(core_config: Res<CoreConfig>, mut rapier_config: ResMut<RapierConfigura
fn copy_coordinates_to_transform( fn copy_coordinates_to_transform(
config: Res<CoreConfig>, config: Res<CoreConfig>,
mut query: Query<(&Coordinates, &mut Transform)>, mut query: Query<(&Coordinates, &mut Transform), Without<RigidBodyPosition>>,
) { ) {
for (coordinates, mut transform) in query.iter_mut() { for (coordinates, mut transform) in query.iter_mut() {
transform.translation.x = coordinates.0 .0 * config.pixels_per_unit as f32; transform.translation.x = coordinates.0 .0 * config.pixels_per_unit as f32;
@ -495,6 +495,15 @@ fn copy_coordinates_to_transform(
} }
} }
fn copy_rigid_body_position_to_coordinates(
mut query: Query<(&mut Coordinates, &RigidBodyPosition)>,
) {
for (mut coordinates, position) in query.iter_mut() {
coordinates.0 .0 = position.position.translation.x;
coordinates.0 .1 = position.position.translation.y;
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct CoreConfig { pub struct CoreConfig {
pub pixels_per_unit: u8, pub pixels_per_unit: u8,
@ -521,6 +530,10 @@ impl Plugin for CorePlugin {
copy_coordinates_to_transform copy_coordinates_to_transform
.system() .system()
.before(TransformSystem::TransformPropagate), .before(TransformSystem::TransformPropagate),
)
.add_system_to_stage(
CoreStage::PostUpdate,
copy_rigid_body_position_to_coordinates.system(),
); );
} }
} }