mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-26 13:32:32 +00:00
4afa0f5d7d
* feat(animation): added example & boilerplate * moved animations specific code to a different module * added multiple robots & foxes * added example of controlling animation based on distance from the player * removed obsolete files * added information about animation to READMEs * updated dependencies closes #26
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
use super::Player;
|
|
use bevy::prelude::*;
|
|
|
|
#[derive(Component, Reflect, Default, Debug)]
|
|
#[reflect(Component)]
|
|
pub struct Pickable;
|
|
|
|
// very simple, crude picking (as in picking up objects) implementation
|
|
|
|
pub fn picking(
|
|
players: Query<&GlobalTransform, With<Player>>,
|
|
pickables: Query<(Entity, &GlobalTransform), With<Pickable>>,
|
|
mut commands: Commands,
|
|
) {
|
|
for player_transforms in players.iter() {
|
|
for (pickable, pickable_transforms) in pickables.iter() {
|
|
let distance = player_transforms
|
|
.translation()
|
|
.distance(pickable_transforms.translation());
|
|
if distance < 2.5 {
|
|
commands.entity(pickable).despawn_recursive();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct PickingPlugin;
|
|
impl Plugin for PickingPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.register_type::<Pickable>().add_systems(
|
|
Update,
|
|
(
|
|
picking, //.run_if(in_state(AppState::Running)),
|
|
),
|
|
);
|
|
}
|
|
}
|