aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/movement/src/lib.rs18
-rw-r--r--plugins/movement/src/position.rs12
-rw-r--r--plugins/movement/src/reducer.rs4
3 files changed, 11 insertions, 23 deletions
diff --git a/plugins/movement/src/lib.rs b/plugins/movement/src/lib.rs
index f7f6ba5..d279d3b 100644
--- a/plugins/movement/src/lib.rs
+++ b/plugins/movement/src/lib.rs
@@ -4,21 +4,23 @@
//!
//! # Included
//!
-//! - **Velocity**: Represents the entity's current momentum, used by systems to calculate the next frame's position
-//! - **Position**: Represents the entity's current location
+//! - **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!(position, velocity, movement);
+import!(velocity, movement);
// Modifiers
import!(reducer);
@@ -35,13 +37,11 @@ impl Plugin for CHMovementPlugins {
}
fn update_movement(
- query: Query<(&mut Position, &mut Velocity, Option<&VelocityReducer>), With<Movement>>,
+ query: Query<(&mut Transform, &mut Velocity, Option<&VelocityReducer>), With<Movement>>,
) {
- for (mut pos, mut velo, reducer) in query {
- // Add Velocity to Position
- pos.x += velo.x;
- pos.y += velo.y;
- pos.z += velo.z;
+ 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 {
diff --git a/plugins/movement/src/position.rs b/plugins/movement/src/position.rs
deleted file mode 100644
index c6dc598..0000000
--- a/plugins/movement/src/position.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-use bevy::{
- ecs::component::Component,
- math::Vec3,
- prelude::{Deref, DerefMut},
-};
-
-/// Used to represent the actual position of the current entity
-#[derive(Component, Deref, DerefMut, PartialEq, Default, Clone)]
-pub struct Position {
- #[deref]
- pos: Vec3,
-}
diff --git a/plugins/movement/src/reducer.rs b/plugins/movement/src/reducer.rs
index 334d37e..4827dd3 100644
--- a/plugins/movement/src/reducer.rs
+++ b/plugins/movement/src/reducer.rs
@@ -5,10 +5,10 @@ use crate::Velocity;
/// Controls how Velocity is reduced
#[derive(Component)]
pub enum VelocityReducer {
- /// Sync mode, only applies the current Velocity to Position each time, does not reduce itself
+ /// Sync mode, only applies the current Velocity to translation each time, does not reduce itself
Sync,
- /// Move mode, directly zeroes out the velocity (momentum is transferred to Position)
+ /// Move mode, directly zeroes out the velocity (momentum is transferred to translation)
Move,
/// Constant reduction mode, reduces by a fixed amount each time until it becomes Vec3::ZERO