//! CH Modules - Movement //! //! CH Movement provides a set of systems for driving Entity movement. //! //! # Included //! //! - **Velocity**: Represents the entity's current momentum, used by systems to calculate the next frame's translation //! - **Movement**: A pure marker, used to flag this entity as movable //! - **VelocityReducer**: Controls how Velocity is reduced //! //! Movement is applied to the entity's [`Transform::translation`]. #![deny(missing_docs)] use bevy::{ app::{FixedUpdate, Plugin}, ecs::{query::With, system::Query}, transform::components::Transform, }; use ch_macro_rules::import; // Basic data import!(velocity, movement); // Modifiers import!(reducer); /// Cigarette Hacker movement plugin /// /// Used to describe the movement of characters in the game pub struct CHMovementPlugin; impl Plugin for CHMovementPlugin { fn build(&self, app: &mut bevy::app::App) { app.add_systems(FixedUpdate, update_movement); } } fn update_movement( query: Query<(&mut Transform, &mut Velocity, Option<&VelocityReducer>), With>, ) { for (mut transform, mut velo, reducer) in query { // Add Velocity to the entity's translation transform.translation += **velo; // Apply velocity reduction (default to Lerp(0.25) if no reducer present) match reducer { Some(reducer) => reducer.calculate(&mut velo), None => VelocityReducer::Lerp(0.25).calculate(&mut velo), } } }