refactor
This commit is contained in:
parent
0181ad7f2d
commit
45fee92eea
6 changed files with 37 additions and 90 deletions
31
src/movable.rs
Normal file
31
src/movable.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
pub struct DamagablePlugin;
|
||||
|
||||
impl Plugin for DamagablePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(Time::<Fixed>::from_hz(60.0))
|
||||
.add_systems(FixedUpdate, movement_system);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Movable {
|
||||
pub linear_speed: f32,
|
||||
pub rotation_speed: f32,
|
||||
pub max_linear_speed: f32,
|
||||
pub max_rotation_speed: f32,
|
||||
}
|
||||
|
||||
fn movement_system(time: Res<Time>, query: Query<(&Movable, &mut Transform)>) {
|
||||
for (movable, mut transform) in query {
|
||||
transform.rotate_z(movable.rotation_speed * time.delta_secs());
|
||||
let movement_direction = transform.rotation * Vec3::X;
|
||||
let movement_distance = movable.linear_speed * time.delta_secs();
|
||||
let translation_delta = movement_direction * movement_distance;
|
||||
|
||||
transform.translation += translation_delta;
|
||||
|
||||
//TODO: Loop on bounds
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue