Adds movement plugin, ball moves now
parent
dcbd33e136
commit
c586c87afe
@ -1,3 +1,4 @@
|
||||
|
||||
|
||||
pub mod core;
|
||||
pub mod core;
|
||||
pub mod movement;
|
||||
@ -0,0 +1,39 @@
|
||||
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct MovementPlugin;
|
||||
impl Plugin for MovementPlugin
|
||||
{
|
||||
fn build(&self, app: &mut App)
|
||||
{
|
||||
app.add_systems(Update, update_movement);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(Vec3);
|
||||
|
||||
impl Default for Velocity
|
||||
{
|
||||
fn default() -> Self
|
||||
{
|
||||
Self { 0: Vec3::new(0.0, 0.0, 0.0)}
|
||||
}
|
||||
}
|
||||
|
||||
impl Velocity
|
||||
{
|
||||
pub fn new(x: f32, y: f32, z: f32) -> Self{
|
||||
Self { 0: Vec3::new(x, y, z) }
|
||||
}
|
||||
}
|
||||
|
||||
// SYSTEMS
|
||||
fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>)
|
||||
{
|
||||
for (velocity, mut transform) in moving_objects.iter_mut()
|
||||
{
|
||||
transform.translation += velocity.0 * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue