Sync rigid body positions with coordinates, and don't sync coordinates for physics objects with transforms
This commit is contained in:
parent
cc249ad4fb
commit
5a6a3efb35
15
src/core.rs
15
src/core.rs
|
@ -487,7 +487,7 @@ fn setup(core_config: Res<CoreConfig>, mut rapier_config: ResMut<RapierConfigura
|
|||
|
||||
fn copy_coordinates_to_transform(
|
||||
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() {
|
||||
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)]
|
||||
pub struct CoreConfig {
|
||||
pub pixels_per_unit: u8,
|
||||
|
@ -521,6 +530,10 @@ impl Plugin for CorePlugin {
|
|||
copy_coordinates_to_transform
|
||||
.system()
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
copy_rigid_body_position_to_coordinates.system(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user