Crates.io | bevy_landmass |
lib.rs | bevy_landmass |
version | |
source | src |
created_at | 2023-06-26 04:20:48.135475 |
updated_at | 2024-11-30 08:39:28.175612 |
description | A plugin for Bevy to handle navigation of AI characters. |
homepage | |
repository | https://github.com/andriyDev/landmass |
max_upload_size | |
id | 900030 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A plugin for Bevy to allow using landmass conveniently.
bevy_landmass
allows using a navigation mesh to determine the desired move
direction for characters using pathfinding.
To use bevy_landmass
:
LandmassPlugin
to your app.Archipelago
component.IslandBundle
, a TransformBundle
(or any other
bundle which includes a Transform
and GlobalTransform
), and an
IslandNavMesh
component.AgentBundle
and a TransformBundle
(or any other
bundle which includes a Transform
and GlobalTransform
).Note the Archipelago
can be created later, even if the agents/islands already
have an ArchipelagoRef
to it. Agents/islands will be added once the
Archipelago
exists.
use std::sync::Arc;
use bevy::{app::AppExit, prelude::*};
use bevy_landmass::{prelude::*, NavMeshHandle};
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(AssetPlugin::default())
.add_plugins(TransformPlugin)
.add_plugins(Landmass2dPlugin::default())
.add_systems(Startup, set_up_scene)
.add_systems(Update, print_desired_velocity.after(LandmassSystemSet::Output))
.add_systems(Update, quit.after(print_desired_velocity))
.run();
}
fn set_up_scene(
mut commands: Commands,
mut nav_meshes: ResMut<Assets<NavMesh2d>>,
) {
let archipelago_id = commands
.spawn(Archipelago2d::new(AgentOptions::default_for_agent_radius(0.5)))
.id();
let nav_mesh_handle = nav_meshes.reserve_handle();
commands
.spawn((
Island2dBundle {
island: Island,
archipelago_ref: ArchipelagoRef2d::new(archipelago_id),
nav_mesh: NavMeshHandle(nav_mesh_handle.clone()),
},
));
// The nav mesh can be populated in another system, or even several frames
// later.
let nav_mesh = Arc::new(NavigationMesh2d {
vertices: vec![
Vec2::new(1.0, 1.0),
Vec2::new(2.0, 1.0),
Vec2::new(2.0, 2.0),
Vec2::new(1.0, 2.0),
Vec2::new(2.0, 3.0),
Vec2::new(1.0, 3.0),
Vec2::new(2.0, 4.0),
Vec2::new(1.0, 4.0),
],
polygons: vec![
vec![0, 1, 2, 3],
vec![3, 2, 4, 5],
vec![5, 4, 6, 7],
],
polygon_type_indices: vec![0, 0, 0],
}.validate().expect("is valid"));
nav_meshes.insert(&nav_mesh_handle, NavMesh2d{
nav_mesh,
type_index_to_node_type: Default::default(),
});
commands.spawn((
Transform::from_translation(Vec3::new(1.5, 1.5, 0.0)),
Agent2dBundle {
agent: Default::default(),
settings: AgentSettings {
radius: 0.5,
desired_speed: 1.0,
max_speed: 2.0,
},
archipelago_ref: ArchipelagoRef2d::new(archipelago_id),
},
AgentTarget2d::Point(Vec2::new(1.5, 3.5)),
));
}
fn print_desired_velocity(query: Query<(Entity, &AgentDesiredVelocity2d)>) {
for (entity, desired_velocity) in query.iter() {
println!(
"entity={:?}, desired_velocity={}",
entity,
desired_velocity.velocity());
}
}
fn quit(mut exit: EventWriter<AppExit>) {
// Quit so doctests pass.
exit.send(AppExit::Success);
}
License under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.