key mesh and squishy animation

This commit is contained in:
2025-03-13 22:11:30 +01:00
parent c358108c56
commit 7281a46521
4 changed files with 27 additions and 15 deletions

View File

@@ -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(