aboutsummaryrefslogtreecommitdiff
path: root/plugins/glues/gravity_movement/src/lib.rs
blob: da3106171bbd6fa237a47461e3d2fe64c00e089b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! CH Glue - Gravity & Movement
//!
//! This module provides the glue layer for the Gravity and Movement modules.

#![deny(missing_docs)]

use bevy::{
    app::{FixedUpdate, Plugin},
    ecs::system::{Query, Res},
};
use ch_gravity::Gravity;
use ch_movement::{Movement, Velocity};

/// Cigarette Hacker gravity movement glue
pub struct CHGravityMovementGluePlugin;

impl Plugin for CHGravityMovementGluePlugin {
    fn build(&self, app: &mut bevy::app::App) {
        app.add_systems(FixedUpdate, apply_gravity_to_movement);
    }
}

fn apply_gravity_to_movement(mut query: Query<(&mut Velocity, &Movement)>, gravity: Res<Gravity>) {
    for (mut velocity, _movement) in query.iter_mut() {
        velocity.x += gravity.x;
        velocity.y += gravity.y;
        velocity.z += gravity.z;
    }
}