From e7fff704c10ba1052680b66cf432efd36dfb5ee8 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 9 Jun 2025 20:55:21 +0300 Subject: [PATCH] feat: allow setting the spawn position --- crates/bevy_dice/src/lib.rs | 4 +++- crates/bevy_dice_demo/src/main.rs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_dice/src/lib.rs b/crates/bevy_dice/src/lib.rs index 113bb60..c0afec9 100644 --- a/crates/bevy_dice/src/lib.rs +++ b/crates/bevy_dice/src/lib.rs @@ -98,6 +98,8 @@ pub struct ThrowDie { pub variant: DieVariant, /// Initial angular velocity, random if not set. pub angular_velocity: Option, + /// Initial position, `Vec3::ZERO` if not set. + pub position: Option, /// Initial rotation, random if not set. pub rotation: Option, } @@ -157,7 +159,7 @@ fn throw_die( }, )], Transform { - translation: Vec3::new(0.0, 4.0, 0.0), + translation: trigger.position.unwrap_or(Vec3::ZERO), rotation: trigger .rotation .unwrap_or_else(|| Quat::from_rng(rng.as_mut())), diff --git a/crates/bevy_dice_demo/src/main.rs b/crates/bevy_dice_demo/src/main.rs index 816edda..c104f1b 100644 --- a/crates/bevy_dice_demo/src/main.rs +++ b/crates/bevy_dice_demo/src/main.rs @@ -194,6 +194,7 @@ fn ui(mut commands: Commands, mut contexts: EguiContexts, mut r_ui_state: ResMut id: r_ui_state.die_id, variant: r_ui_state.selected_variant, angular_velocity: None, + position: Some(Vec3::new(0.0, 4.0, 0.0)), rotation: None, }); r_ui_state.die_id += 1; -- 2.44.1