crystal.Navigation
A Component which allows entities to find and follow paths.
This component only works with the following setup:
Even though methods on this component return threads, the entity does not need a ScriptRunner component. The Navigation component manages its own Script, and updates it via update_navigation.
Constructor
Like all other components, Navigation components are created by calling Entity:add_component.
The constructor for Navigation expects an argument of type Map.
Methods
| Name | Description |
|---|---|
| align_with_entity | Begins moving to align itself vertically or horizontally with another entity. |
| navigate_to_entity | Begins moving towards another entity. |
| navigate_to | Begins moving towards a specific location. |
| set_acceptance_radius | Sets the default acceptance radius for navigation requests on this component. |
| set_repath_delay | Sets the default repath delay for navigation requests on this component. |
| update_navigation | Sets heading to follow current path. |
Examples
local map = crystal.assets.get("assets/map/castle_courtyard.lua");
local ecs = crystal.ECS:new();
local physics_system = ecs:add_system(crystal.PhysicsSystem);
local ai_system = ecs:add_system(crystal.AISystem, map);
local entity = ecs:spawn(crystal.Entity);
entity:add_component(crystal.Body);
entity:add_component(crystal.Movement);
entity:add_component(crystal.Navigation);
entity:navigate_to(60, 120);
-- During update:
physics_system:simulate_physics(dt);
ai_system:update_ai(dt);