From ad93807304c07c0c11883fb0e3aab044f1ee4e5f Mon Sep 17 00:00:00 2001 From: GStudiosX2 <76548041+GStudiosX2@users.noreply.github.com> Date: Sun, 5 Jul 2026 20:40:11 +0100 Subject: [PATCH 1/2] [feat] Simple friction physics --- src/game_systems/src/lib.rs | 1 + src/game_systems/src/physics/src/friction.rs | 14 ++++++++++++++ src/game_systems/src/physics/src/lib.rs | 1 + 3 files changed, 16 insertions(+) create mode 100644 src/game_systems/src/physics/src/friction.rs diff --git a/src/game_systems/src/lib.rs b/src/game_systems/src/lib.rs index f403a72d..5640d739 100644 --- a/src/game_systems/src/lib.rs +++ b/src/game_systems/src/lib.rs @@ -127,6 +127,7 @@ fn register_tick_systems(schedule: &mut Schedule) { physics::unground::handle, physics::gravity::handle, physics::drag::handle, + physics::friction::handle, physics::velocity::handle, physics::collisions::handle, physics::chunk_boundary::handle, diff --git a/src/game_systems/src/physics/src/friction.rs b/src/game_systems/src/physics/src/friction.rs new file mode 100644 index 00000000..326708f0 --- /dev/null +++ b/src/game_systems/src/physics/src/friction.rs @@ -0,0 +1,14 @@ +use bevy_ecs::system::Query; +use bevy_math::Vec3A; +use temper_components::player::velocity::Velocity; + +pub fn handle(mut query: Query<&mut Velocity>) { + for mut vel in query.iter_mut() { + //TODO: proper dampen + if vel.length() <= 0.001 { + **vel = Vec3A::ZERO; + } + const DAMPEN_AMOUNT: Vec3A = Vec3A::new(0.9, 0.99, 0.9); + **vel *= DAMPEN_AMOUNT; + } +} diff --git a/src/game_systems/src/physics/src/lib.rs b/src/game_systems/src/physics/src/lib.rs index c19a9f18..07df870f 100644 --- a/src/game_systems/src/physics/src/lib.rs +++ b/src/game_systems/src/physics/src/lib.rs @@ -1,6 +1,7 @@ pub mod chunk_boundary; pub mod collisions; pub mod drag; +pub mod friction; pub mod gravity; pub mod unground; pub mod velocity; From 01c48a1c2959e253857f540777ec25293c424305 Mon Sep 17 00:00:00 2001 From: GStudiosX2 <76548041+GStudiosX2@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:01:34 +0100 Subject: [PATCH 2/2] [feat] add motion command --- src/default_commands/src/lib.rs | 1 + src/default_commands/src/motion.rs | 55 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/default_commands/src/motion.rs diff --git a/src/default_commands/src/lib.rs b/src/default_commands/src/lib.rs index 6a25abc0..177962cb 100644 --- a/src/default_commands/src/lib.rs +++ b/src/default_commands/src/lib.rs @@ -3,6 +3,7 @@ mod credits; pub mod echo; pub mod gamemode; mod kill; +mod motion; pub mod op; mod stop; mod summon; diff --git a/src/default_commands/src/motion.rs b/src/default_commands/src/motion.rs new file mode 100644 index 00000000..35e78841 --- /dev/null +++ b/src/default_commands/src/motion.rs @@ -0,0 +1,55 @@ +use bevy_ecs::prelude::{Entity, Query}; +use bevy_ecs::query::Without; +use temper_command_infra::args::{EntitiesArg, PositionArg}; +use temper_command_infra::{CommandHandler, CommandResult, CommandSource}; +use temper_components::entity_identity::Identity; +use temper_components::player::player_marker::PlayerMarker; +use temper_components::player::position::Position; +use temper_components::player::velocity::Velocity; +use temper_macros::Command; +use temper_permissions::Permissions; + +#[derive(Debug, Command)] +#[command(name = "motion", permission = Permissions::Op)] +struct MotionCommand { + target: EntitiesArg, + offset: PositionArg, +} + +impl CommandHandler for MotionCommand { + type SystemParam<'w, 's> = ( + Query<'w, 's, (Entity, &'static Identity, Option<&'static PlayerMarker>)>, + Query<'w, 's, (&'static Identity, &'static mut Velocity), Without>, + ); + + fn handle( + self, + source: CommandSource, + params: &mut Self::SystemParam<'_, '_>, + ) -> CommandResult { + let (entity_query, motion_targets) = params; + + let entities = self.target.resolve(entity_query.iter()); + + let offset = self.offset.resolve(&Position::new(0f64, 0f64, 0f64)); + + for entity in &entities { + if let Ok((_, mut velocity)) = motion_targets.get_mut(*entity) { + velocity.vec += offset.as_vec3a(); + } + } + + source.send_message( + format!( + "Added velocity of ~{} ~{} ~{} for {} entitie(s)", + offset.x, + offset.y, + offset.z, + entities.len() + ) + .into(), + ); + + Ok(()) + } +}