Skip to content

Commit

Permalink
Allow scale sync opt-out
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Sep 10, 2024
1 parent ace2570 commit 42dbb28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/collision/collider/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::marker::PhantomData;

use crate::{broad_phase::BroadPhaseSet, prelude::*, prepare::PrepareSet};
use crate::{broad_phase::BroadPhaseSet, prelude::*, prepare::PrepareSet, sync::SyncConfig};
#[cfg(all(feature = "bevy_scene", feature = "default-collider"))]
use bevy::scene::SceneInstance;
use bevy::{
Expand Down Expand Up @@ -642,7 +642,12 @@ pub fn update_collider_scale<C: ScalableCollider>(
// Child colliders
Query<(&ColliderTransform, &mut C), (With<Parent>, Changed<ColliderTransform>)>,
)>,
sync_config: Res<SyncConfig>,
) {
if !sync_config.transform_to_collider_scale {
return;
}

// Update collider scale for root bodies
for (transform, mut collider) in &mut colliders.p0() {
#[cfg(feature = "2d")]
Expand Down
14 changes: 12 additions & 2 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,32 @@ impl Plugin for SyncPlugin {
}
}

/// Configures what physics data is synchronized by the [`SyncPlugin`] and how.
/// Configures what physics data is synchronized by the [`SyncPlugin`] and [`PreparePlugin`] and how.
#[derive(Resource, Reflect, Clone, Debug, PartialEq, Eq)]
#[reflect(Resource)]
pub struct SyncConfig {
/// Updates transforms based on [`Position`] and [`Rotation`] changes. Defaults to true.
///
/// This operation is run in [`SyncSet::PositionToTransform`].
pub position_to_transform: bool,
/// Updates [`Position`] and [`Rotation`] based on transform changes,
/// allowing you to move bodies using `Transform`. Defaults to true.
/// allowing you to move bodies using [`Transform`]. Defaults to true.
///
/// This operation is run in [`SyncSet::TransformToPosition`].
pub transform_to_position: bool,
/// Updates [`Collider::scale()`] based on transform changes,
/// allowing you to scale colliders using [`Transform`]. Defaults to true.
///
/// This operation is run in [`PrepareSet::Finalize`]
pub transform_to_collider_scale: bool,
}

impl Default for SyncConfig {
fn default() -> Self {
SyncConfig {
position_to_transform: true,
transform_to_position: true,
transform_to_collider_scale: true,
}
}
}
Expand Down

0 comments on commit 42dbb28

Please sign in to comment.