Ladies and gentlemen... we have a bouncing bird

main
Elijah Voigt 3 months ago
parent 9c4b4a79b9
commit e7693c747c

@ -4,9 +4,13 @@ fn main() {
App::new() App::new()
.add_plugins(BaseGamePlugin { name: "flappy bird (with rewind)".into() }) .add_plugins(BaseGamePlugin { name: "flappy bird (with rewind)".into() })
.add_systems(Startup, init_bird) .add_systems(Startup, init_bird)
.add_systems(Update, flap)
.run(); .run();
} }
#[derive(Component)]
struct Bird;
fn init_bird( fn init_bird(
mut commands: Commands, mut commands: Commands,
server: Res<AssetServer>, server: Res<AssetServer>,
@ -29,8 +33,21 @@ fn init_bird(
let mass = ( let mass = (
RigidBody::Dynamic, RigidBody::Dynamic,
Collider::capsule(1.0, 1.0), Collider::capsule(1.0, 1.0),
Mass(5.0), Mass(1.0),
); );
commands.spawn((name, mesh, material, mass, t)); let force = ExternalForce::default().with_persistence(false);
commands.spawn((name, mesh, material, mass, t, Bird, force));
}
fn flap(
keyboard: Res<ButtonInput<KeyCode>>,
mut bird: Query<(&Transform, &mut ExternalForce), With<Bird>>,
) {
if keyboard.just_pressed(KeyCode::Space) {
bird.iter_mut().for_each(|(t, mut f)| {
f.apply_force(t.rotation * Vec3::NEG_Z * 1000.0);
});
}
} }

Loading…
Cancel
Save