-
Reading through the breakout example I've noticed that single functions have been chosen to handle the functionality of all components1.
This begs the question: What if components have individual functionality such as differing speed and/or acceleration? Movement and any other attributes that apply to specific components would have to be handled on an individual level. Given components with individual properties: #[derive(Component)]
struct Projectile {
position: Vec2,
velocity: Vec2
}
#[derive(Component)]
struct Enemy {
health: i32
} How might one go about using Footnotes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You have different options:
/// The current acceleration, so the speed can augment progressively
#[derive(Component)]
struct Acceleration {
current: f32,
}
/// a configuration for each entity, like the acceleration rate.
#[derive(Component)]
struct AccelerationChange {
change_per_frame: f32,
}
/// Another configuration to know when the acceleration is too much, or not get an unsupported speed.
#[derive(Component)]
struct MaxSpeed(f32);
#[derive(Component)]
struct MarkerFastProjectile;
#[derive(Component)]
struct MarkerSinProjectile;
fn system_move_fast(mut q_projectiles: Query<&mut Transform, With<MarkerFastProjectile>>) {
for t in q_projectiles.iter() {
// We could modify Speed, to defer actual movement to another system
t.translation += Vec3::X * 5f32;
}
}
fn system_move_sin(time: Res<Time>, mut q_projectiles: Query<&mut Transform, With<MarkerSinProjectile>>) {
for t in q_projectiles.iter() {
t.translation += Vec3::X * 1f32 + Vec3::Y * time.elapsed_seconds().sin();
}
} |
Beta Was this translation helpful? Give feedback.
You have different options:
Resource
, might be interesting if you have multiple similarly configured entities.