Lightyear setup (#55)

This commit is contained in:
extrawurst
2025-07-10 23:21:11 +02:00
committed by GitHub
parent 691b9eed33
commit 78b09b33d6
26 changed files with 2515 additions and 242 deletions

View File

@@ -5,9 +5,10 @@ use crate::{
heads_database::HeadsDatabase,
loading_assets::GameAssets,
physics_layers::GameLayer,
protocol::GltfSceneRoot,
sounds::PlaySound,
utils::{
auto_rotate::AutoRotation, explosions::Explosion, global_observer,
auto_rotate::AutoRotation, commands::CommandExt, explosions::Explosion, global_observer,
sprite_3d_animation::AnimationTimer,
},
};
@@ -15,10 +16,12 @@ use avian3d::prelude::*;
use bevy::{pbr::NotShadowCaster, prelude::*};
use bevy_ballistic::launch_velocity;
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
use lightyear::prelude::{NetworkTarget, Replicate};
use serde::{Deserialize, Serialize};
use std::f32::consts::PI;
#[derive(Component)]
struct ThrownProjectile {
#[derive(Component, Serialize, Deserialize, PartialEq)]
pub struct ThrownProjectile {
impact_animation: bool,
damage: u32,
}
@@ -50,8 +53,6 @@ fn on_trigger_thrown(
trigger: Trigger<TriggerThrow>,
mut commands: Commands,
query_transform: Query<&Transform>,
assets: Res<GameAssets>,
gltf_assets: Res<Assets<Gltf>>,
heads_db: Res<HeadsDatabase>,
) {
let state = trigger.event().0;
@@ -76,8 +77,6 @@ fn on_trigger_thrown(
};
let head = heads_db.head_stats(state.head);
let mesh = assets.projectiles[format!("{}.glb", head.projectile).as_str()].clone();
let asset = gltf_assets.get(&mesh).unwrap();
//TODO: projectile db?
let explosion_animation = !matches!(state.head, 8 | 16);
@@ -102,9 +101,10 @@ fn on_trigger_thrown(
Visibility::default(),
Sensor,
))
.insert_server(Replicate::to_clients(NetworkTarget::All))
.with_child((
AutoRotation(Quat::from_rotation_x(0.4) * Quat::from_rotation_z(0.3)),
SceneRoot(asset.scenes[0].clone()),
GltfSceneRoot::Projectile(head.projectile.clone()),
));
}