key mesh and squishy animation
This commit is contained in:
BIN
assets/models/key.glb
Normal file
BIN
assets/models/key.glb
Normal file
Binary file not shown.
20
src/keys.rs
20
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<KeySpawn>,
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
fn on_spawn(trigger: Trigger<KeySpawn>, mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
20
src/squish_animation.rs
Normal file
20
src/squish_animation.rs
Normal file
@@ -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<Time>) {
|
||||
for (mut transform, keymesh) in query.iter_mut() {
|
||||
transform.scale = Vec3::new(
|
||||
keymesh.0,
|
||||
keymesh.0 + (sin(time.elapsed_secs() * 6.) * 0.2),
|
||||
keymesh.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user