Expand description
§bevy_landmass
A plugin for Bevy to allow using landmass conveniently.
§Overview
bevy_landmass allows using a navigation mesh to determine the desired move
direction for characters using pathfinding.
To use bevy_landmass:
- Add
LandmassPluginto your app. - Spawn an entity with an
Archipelagocomponent. - Spawn an entity with an
IslandBundle, aTransformBundle(or any other bundle which includes aTransformandGlobalTransform), and anIslandNavMeshcomponent. - Spawn entities with the
AgentBundleand aTransformBundle(or any other bundle which includes aTransformandGlobalTransform).
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.
§Example
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)
.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(ArchipelagoOptions::from_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],
height_mesh: None,
}.validate().expect("is valid"));
nav_meshes.insert(&nav_mesh_handle, NavMesh2d { nav_mesh });
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: MessageWriter<AppExit>) {
// Quit so doctests pass.
exit.write(AppExit::Success);
}§License
License under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
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.
Modules§
Structs§
- Agent
- A marker component to create all required components for an agent.
- Agent
Bundle - A bundle to create agents. This omits the GlobalTransform component, since this is commonly added in other bundles (which is redundant and can override previous bundles).
- Agent
Desired Velocity - The current desired velocity of the agent. This is set by
landmass(during [crate::LandmassSystemSet::Output]). - Agent
Settings - The settings for an agent. See
crate::AgentBundlefor required related components. - Agent
Type Index Cost Overrides - Animation
Link - A link connecting two edges where an agent must perform some action (or animation) to use the link.
- Animation
Link Bundle - A bundle to create animation links.
- Animation
Link Reached Distance - The distance at which an animation link can be used.
- Archipelago
- An archipelago, holding the internal state of
landmass. - Archipelago
Options - Options that apply to the entire archipelago.
- Archipelago
Ref - A reference to an archipelago.
- Character
- A marker component to create all required components for a character.
- Character
Bundle - A bundle to create characters. This omits the GlobalTransform component, since this is commonly added in other bundles (which is redundant and can override previous bundles).
- Character
Settings - A character’s settings. See
crate::CharacterBundlefor required related components. - Height
Navigation Mesh - An (optional) part of the navigation mesh dedicated to “refining” the height of a point.
- Height
Polygon - A polygon specifically for “refining” the height of a point.
- Island
- A marker component that an entity is an island.
- Island
Bundle - A bundle to create islands. The GlobalTransform component is omitted, since this is commonly added in other bundles (which is redundant and can override previous bundles).
- Landmass
Plugin - NavMesh
- An asset holding a
landmassnav mesh. - NavMesh
Handle - A handle to a navigation mesh for an
Island. - Navigation
Mesh - A navigation mesh.
- Pause
Agent - A marker component to indicate that an agent should be paused.
- Point
Sample Distance3d - A
PointSampleDistancetype for 3D coordinate systems. - Reached
Animation Link - An animation link that an agent has reached (in order to use it).
- Sampled
Point - A point on the navigation meshes.
- Using
Animation Link - A marker component to indicate that an agent is currently using an animation
link and should behave as though it is paused (see
PauseAgentfor details). - Valid
Navigation Mesh - A navigation mesh which has been validated and derived data has been computed.
- Velocity
- The current velocity of the agent/character. This must be set to match whatever speed the agent/character is going.
Enums§
- Agent
State - The state of an agent.
- Agent
Target - The current target of the entity. Note this can be set by either reinserting the component, or dereferencing:
- Find
Path Error - An error from finding a path between two sampled points.
- Landmass
Systems - System set for
landmasssystems. - Path
Step - A single step in a path.
- Permitted
Animation Links - Defines the list of animation links that an agent is allowed to use.
- Sample
Point Error - An error while sampling a point.
- SetType
Index Cost Error - An error for settings the cost of a type index.
- Target
Reached Condition - The condition to consider the agent as having reached its target. When this condition is satisfied, the agent will stop moving.
- Validation
Error - An error when validating a navigation mesh.
Traits§
- From
Agent Radius - A trait to create a default instance based on an agent’s radius.
Type Aliases§
- Agent2d
- Agent2d
Bundle - Agent3d
- Agent3d
Bundle - Agent
Desired Velocity2d - Agent
Desired Velocity3d - Agent
Target2d - Agent
Target3d - Animation
Link2d - Animation
Link2d Bundle - Animation
Link3d - Animation
Link3d Bundle - Archipelago2d
- Archipelago3d
- Archipelago
Ref2d - Archipelago
Ref3d - Character2d
Bundle - Character3d
Bundle - Height
Navigation Mesh2d - Height
Navigation Mesh3d - Island2d
Bundle - Island3d
Bundle - Landmass2d
Plugin - Landmass3d
Plugin - NavMesh2d
- NavMesh3d
- NavMesh
Handle2d - NavMesh
Handle3d - Navigation
Mesh2d NavigationMeshusing 2D Bevy coordinates. That means that the mesh expects vertices to be on the XY plane.- Navigation
Mesh3d NavigationMeshusing 3D Bevy coordinates. That means that the mesh expects vertices to be in- Reached
Animation Link2d - Reached
Animation Link3d - Valid
Navigation Mesh2d - Valid
Navigation Mesh3d - Velocity2d
- Velocity3d