Crate bevy_spatial
source · [−]Expand description
A bevy plugin to track your entities in spatial indexes and query them.
Quickstart using the kdtree
feature:
use bevy_spatial::{KDTreeAccess2D, KDTreePlugin2D, SpatialAccess};
#[derive(Component)]
struct TrackedByKDTree;
fn main() {
App::new()
.add_plugin(KDTreePlugin2D::<TrackedByKDTree> { ..default() })
// ...
}
type NNTree = KDTreeAccess2D<TrackedByKDTree>; // type alias for later
fn (tree: Res<NNTree>){
if let Some((pos, entity)) = tree.nearest_neighbour(Vec2::ZERO) {
// pos: Vec3
// do something with the nearest entity here
}
}
For more details see Examples
Structs
The core plugin struct which stores metadata for updating and recreating the choosen spatial index.