diff --git a/assets/models/key.glb b/assets/models/key.glb new file mode 100644 index 0000000..dff484c Binary files /dev/null and b/assets/models/key.glb differ diff --git a/src/keys.rs b/src/keys.rs index 1b43f2e..024a969 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -1,4 +1,4 @@ -use crate::player::Player; +use crate::{billboards::Billboard, player::Player, squish_animation::SquishAnimation}; use avian3d::prelude::*; use bevy::prelude::*; use std::f32::consts::PI; @@ -18,19 +18,14 @@ pub fn plugin(app: &mut App) { app.add_observer(on_spawn); } -fn on_spawn( - trigger: Trigger, - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { +fn on_spawn(trigger: Trigger, mut commands: Commands, asset_server: Res) { let KeySpawn(position) = trigger.event(); - let mesh = meshes.add(Cylinder::default()); - //TODO: randomize let spawn_dir = Quat::from_rotation_y(PI / 2.) * Vec3::new(0.5, 0.6, 0.).normalize(); + let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/key.glb")); + commands .spawn(( Name::new("key"), @@ -43,12 +38,7 @@ fn on_spawn( RigidBody::Dynamic, Restitution::new(0.6), )) - .with_child(( - Transform::from_scale(Vec3::new(2.2, 0.4, 2.2)) - .with_rotation(Quat::from_rotation_x(PI / 2.)), - Mesh3d(mesh), - MeshMaterial3d(materials.add(Color::srgb(0., 0., 0.9))), - )); + .with_child((Billboard, SquishAnimation(2.6), SceneRoot(mesh))); } fn collect_key( diff --git a/src/main.rs b/src/main.rs index fccda75..d32c648 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod npc; mod platforms; mod player; mod shooting; +mod squish_animation; mod tb_entities; use avian3d::PhysicsPlugins; @@ -84,6 +85,7 @@ fn main() { app.add_plugins(shooting::plugin); app.add_plugins(npc::plugin); app.add_plugins(keys::plugin); + app.add_plugins(squish_animation::plugin); app.insert_resource(AmbientLight { color: Color::WHITE, diff --git a/src/squish_animation.rs b/src/squish_animation.rs new file mode 100644 index 0000000..feae5ab --- /dev/null +++ b/src/squish_animation.rs @@ -0,0 +1,20 @@ +use bevy::prelude::*; +use ops::sin; + +#[derive(Component, Reflect)] +#[reflect(Component)] +pub struct SquishAnimation(pub f32); + +pub fn plugin(app: &mut App) { + app.add_systems(Update, update); +} + +fn update(mut query: Query<(&mut Transform, &SquishAnimation)>, time: Res