Vleue Navigator Logo

Vleue Navigator

Efficient NavMesh and pathfinding solutions for your Bevy projects

Features

How to Use

Installation

cargo add vleue_navigator

Usage

First add the plugins to your game:
use vleue_navigator::prelude::*;

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            VleueNavigatorPlugin,
            // Auto update navmesh using the `Aabb` component
            NavmeshUpdaterPlugin::::default(),
        ))
        ...
        .run();
}
You can then spawn a NavMesh entity:
fn spawn_navmesh(mut commands: Commands) {
    commands.spawn(NavMeshBundle {
        settings: NavMeshSettings {
            // Define the outer borders of the navmesh.
            fixed: Triangulation::from_outer_edges(&[
                vec2(0.0, 0.0), vec2(10.0, 0.0),
                vec2(10.0, 10.0), vec2(0.0, 10.0),
            ]),
            ..default()
        },
        // Mark it for update as soon as obstacles are changed.
        // Other modes available are debounced or manually triggered.
        update_mode: NavMeshUpdateMode::Direct,
        ..NavMeshBundle::with_default_id()
    });
}
Using the NavMesh to find a path:
pub fn find_path(navmeshes: Res>, navmesh: Query<(&Handle, Ref)>) {
    let (navmesh_handle, status) = navmesh.single();
    if status != NavMeshStatus::Built {
        // NavMesh is not ready yet.
        return;
    }
    if let Some(navmesh) = navmeshes.get_mut(navmesh_handle) {
        let mut rng = rand::thread_rng();
        let from = vec2(rng.gen_range(0.0..10.0), rng.gen_range(0.0..10.0));
        let to = vec2(rng.gen_range(0.0..10.0), rng.gen_range(0.0..10.0));

        if let Some(path) = navmesh.path(from, to) {
            info!("found path from {:?} to {:?}: {:?}", from, to, path);
        } else {
            info!("no path found from {:?} to {:?}", from, to);
        }
    }
}

Examples

Auto updating a NavMesh from Bevy shapes
Auto updating a NavMesh from Bevy shapes
Auto updating a NavMesh from Bevy Aabb component
Auto updating a NavMesh from Bevy `Aabb` component
NavMesh updated using primitive shapes
NavMesh updated using primitive shapes (rectangle, circle, ...)
Overlapping layers
Overlapping layers

Avian integration

Auto updating a NavMesh with colliders from Avian2d
Auto updating a NavMesh with colliders from Avian2d
Auto updating a NavMesh with colliders from Avian3d
Auto updating a NavMesh with colliders from Avian3d

Others

Spawn many agents and run a lot of concurrent pathfinding tasks
Spawn many agents and run a lot of concurrent pathfinding tasks
Showing path lines
Showing path lines
Moving a dot around the meshes
Moving a dot around the meshes
Loading a navmesh from a gLTF file
Loading a navmesh from a gLTF file
Navmesh from random obstacles
Navmesh from random obstacles
Demo to test NavMesh settings
Demo to test NavMesh settings

Reading List of implemented and used techniques

Showcase Videos