trails and better missile origin
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use crate::{GameState, heads_database::HeadsDatabase, loading_assets::GameAssets};
|
||||
use bevy::{ecs::system::SystemParam, platform::collections::HashMap, prelude::*};
|
||||
use crate::{
|
||||
GameState, heads_database::HeadsDatabase, loading_assets::GameAssets, utils::trail::Trail,
|
||||
};
|
||||
use bevy::{
|
||||
ecs::system::SystemParam, platform::collections::HashMap, prelude::*, scene::SceneInstanceReady,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
@@ -34,12 +38,12 @@ pub struct CharacterAnimations {
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
(spawn, setup_once_loaded, setup_projectile_origin).run_if(in_state(GameState::Playing)),
|
||||
(spawn, setup_once_loaded).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
#[cfg(feature = "dbg")]
|
||||
app.add_systems(
|
||||
Update,
|
||||
debug_show_projectile_origin.run_if(in_state(GameState::Playing)),
|
||||
debug_show_projectile_origin_and_trial.run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,29 +67,56 @@ fn spawn(
|
||||
});
|
||||
let asset = gltf_assets.get(handle).unwrap();
|
||||
|
||||
commands.entity(entity).insert((
|
||||
Transform::from_translation(Vec3::new(0., -1.45, 0.)).with_scale(Vec3::splat(1.2)),
|
||||
SceneRoot(asset.scenes[0].clone()),
|
||||
));
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert((
|
||||
Transform::from_translation(Vec3::new(0., -1.45, 0.)).with_scale(Vec3::splat(1.2)),
|
||||
SceneRoot(asset.scenes[0].clone()),
|
||||
))
|
||||
.observe(find_marker_bones);
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_projectile_origin(
|
||||
fn find_marker_bones(
|
||||
trigger: Trigger<SceneInstanceReady>,
|
||||
mut commands: Commands,
|
||||
query: Query<Entity, Added<AnimationPlayer>>,
|
||||
descendants: Query<&Children>,
|
||||
name: Query<&Name>,
|
||||
mut gizmo_assets: ResMut<Assets<GizmoAsset>>,
|
||||
) {
|
||||
for character in query.iter() {
|
||||
for child in descendants.iter_descendants(character) {
|
||||
let Ok(name) = name.get(child) else {
|
||||
continue;
|
||||
};
|
||||
if name.as_str() == "ProjectileOrigin" {
|
||||
commands.entity(child).insert(ProjectileOrigin);
|
||||
}
|
||||
let entity = trigger.target();
|
||||
|
||||
let mut origin_found = false;
|
||||
for child in descendants.iter_descendants(entity) {
|
||||
let Ok(name) = name.get(child) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if name.as_str() == "ProjectileOrigin" {
|
||||
commands.entity(child).insert(ProjectileOrigin);
|
||||
origin_found = true;
|
||||
} else if name.as_str().starts_with("Trail") {
|
||||
commands.entity(child).insert((
|
||||
Trail::new(
|
||||
20,
|
||||
LinearRgba::new(1., 1.0, 1., 0.5),
|
||||
LinearRgba::new(1., 1., 1., 0.5),
|
||||
),
|
||||
Gizmo {
|
||||
handle: gizmo_assets.add(GizmoAsset::default()),
|
||||
line_config: GizmoLineConfig {
|
||||
width: 20.,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if !origin_found {
|
||||
error!("ProjectileOrigin not found");
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_once_loaded(
|
||||
@@ -142,9 +173,9 @@ fn setup_once_loaded(
|
||||
}
|
||||
|
||||
#[cfg(feature = "dbg")]
|
||||
fn debug_show_projectile_origin(
|
||||
fn debug_show_projectile_origin_and_trial(
|
||||
mut gizmos: Gizmos,
|
||||
query: Query<&GlobalTransform, With<ProjectileOrigin>>,
|
||||
query: Query<&GlobalTransform, Or<(With<ProjectileOrigin>, With<Trail>)>>,
|
||||
) {
|
||||
for projectile_origin in query.iter() {
|
||||
gizmos.sphere(
|
||||
|
||||
Reference in New Issue
Block a user