use ProjectileOrigin joint (#36)
This commit is contained in:
@@ -2,6 +2,9 @@ use crate::{GameState, heads_database::HeadsDatabase, loading_assets::GameAssets
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct ProjectileOrigin;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct AnimatedCharacter(pub usize);
|
||||
|
||||
@@ -17,7 +20,12 @@ pub struct CharacterAnimations {
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
(spawn, setup_once_loaded).run_if(in_state(GameState::Playing)),
|
||||
(spawn, setup_once_loaded, setup_projectile_origin).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
#[cfg(feature = "dbg")]
|
||||
app.add_systems(
|
||||
Update,
|
||||
debug_show_projectile_origin.run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,6 +56,24 @@ fn spawn(
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_projectile_origin(
|
||||
mut commands: Commands,
|
||||
query: Query<Entity, Added<AnimationPlayer>>,
|
||||
descendants: Query<&Children>,
|
||||
name: Query<&Name>,
|
||||
) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_once_loaded(
|
||||
mut commands: Commands,
|
||||
mut query: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>,
|
||||
@@ -100,3 +126,17 @@ fn setup_once_loaded(
|
||||
.insert(animations);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "dbg")]
|
||||
fn debug_show_projectile_origin(
|
||||
mut gizmos: Gizmos,
|
||||
query: Query<&GlobalTransform, With<ProjectileOrigin>>,
|
||||
) {
|
||||
for projectile_origin in query.iter() {
|
||||
gizmos.sphere(
|
||||
Isometry3d::from_translation(projectile_origin.translation()),
|
||||
0.1,
|
||||
Color::linear_rgb(0., 1., 0.),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user