mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 20:00:53 +00:00
c4e83655f3
* chore(bevy_gltf_components): updated code for bevy_main/ v0.12 * refactor(examples): cleanups & tweaks * added compatibility tables
35 lines
1020 B
Rust
35 lines
1020 B
Rust
use super::Player;
|
|
use bevy::prelude::*;
|
|
use bevy_gltf_blueprints::GltfBlueprintsSet;
|
|
|
|
#[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.after(GltfBlueprintsSet::AfterSpawn),));
|
|
}
|
|
}
|