simvx.core.navigation¶
2D Navigation and Pathfinding for SimVX.
Provides graph-based and grid-based A* pathfinding, plus a NavigationAgent2D node that follows computed paths with steering and emits signals on arrival.
Usage: from simvx.core import AStar2D, AStarGrid2D, NavigationAgent2D
# Graph-based pathfinding
astar = AStar2D()
astar.add_point(0, (0, 0))
astar.add_point(1, (10, 0))
astar.connect_points(0, 1)
path = astar.get_point_path(0, 1) # [(0,0), (10,0)]
# Grid-based pathfinding
grid = AStarGrid2D(20, 20, cell_size=32.0)
grid.set_solid(5, 5)
path = grid.find_path((0, 0), (10, 10))
# Navigation agent node
agent = NavigationAgent2D()
agent.set_navigation(astar)
agent.target_position = (10, 0)
Module Contents¶
Classes¶
Graph-based A* pathfinding. Supports both grid-based and arbitrary graphs. |
|
Grid-based A* with automatic cell management. |
|
2D node that follows A* paths with steering. |
Data¶
API¶
- simvx.core.navigation.__all__¶
[‘AStar2D’, ‘AStarGrid2D’, ‘NavigationAgent2D’]
- class simvx.core.navigation.AStar2D[source]¶
Graph-based A* pathfinding. Supports both grid-based and arbitrary graphs.
Initialization
- __slots__¶
(‘_points’, ‘_connections’, ‘_weights’, ‘_disabled’)
- add_point(id: int, position: tuple[float, float], weight: float = 1.0)[source]¶
Add a point to the graph. Weight scales traversal cost (default 1.0).
- connect_points(id1: int, id2: int, bidirectional: bool = True)[source]¶
Connect two points. Both must already exist.
- disconnect_points(id1: int, id2: int, bidirectional: bool = True)[source]¶
Remove connection between two points.
- set_point_disabled(id: int, disabled: bool = True)[source]¶
Disable/enable a point. Disabled points are excluded from pathfinding.
- get_closest_point(position: tuple[float, float]) → int[source]¶
Return id of the closest non-disabled point to the given position.
- class simvx.core.navigation.AStarGrid2D(width: int, height: int, cell_size: float = 1.0, diagonal: bool = True, offset: tuple[float, float] = (0.0, 0.0))[source]¶
Grid-based A* with automatic cell management.
Args: width: Grid width in cells. height: Grid height in cells. cell_size: Size of each cell in world units. diagonal: Allow diagonal movement (default True). offset: World-space offset of the grid origin.
Initialization
- __slots__¶
(‘_width’, ‘_height’, ‘_cell_size’, ‘_diagonal’, ‘_offset’, ‘_solid’, ‘_weights’)
- property width: int¶
- property height: int¶
- property cell_size: float¶
- set_solid(x: int, y: int, solid: bool = True)[source]¶
Mark a cell as solid (impassable) or clear it.
- set_weight(x: int, y: int, weight: float)[source]¶
Set traversal weight for a cell. Default is 1.0; higher = costlier.
- class simvx.core.navigation.NavigationAgent2D(max_speed: float = 100.0, path_desired_distance: float = 4.0, **kwargs)[source]¶
Bases:
simvx.core.nodes_2d.node2d.Node2D2D node that follows A* paths with steering.
Assign a pathfinder (AStar2D or AStarGrid2D) via
set_navigation(), settarget_position, and the agent moves toward it each physics frame.Emits
navigation_finishedwhen the target is reached.Usage: agent = NavigationAgent2D(max_speed=200.0) agent.set_navigation(my_astar) agent.target_position = Vec2(500, 300)
Initialization
- max_speed¶
‘Property(…)’
- path_desired_distance¶
‘Property(…)’
- property target_position: simvx.core.math.types.Vec2¶
- property velocity: simvx.core.math.types.Vec2¶
Current velocity (read-only, computed each physics frame).
- property is_navigation_finished: bool¶
- set_navigation(nav: simvx.core.navigation.AStar2D | simvx.core.navigation.AStarGrid2D)[source]¶
Assign a pathfinder instance.
- z_index¶
‘Property(…)’
- z_as_relative¶
‘Property(…)’
- render_layer¶
‘Property(…)’
- set_render_layer(index: int, enabled: bool = True) → None¶
- is_on_render_layer(index: int) → bool¶
- property absolute_z_index: int¶
- property position: simvx.core.math.types.Vec2¶
- property rotation: float¶
- property rotation_degrees: float¶
- property scale: simvx.core.math.types.Vec2¶
- property world_position: simvx.core.math.types.Vec2¶
- property world_rotation: float¶
- property world_scale: simvx.core.math.types.Vec2¶
- property forward: simvx.core.math.types.Vec2¶
- property right: simvx.core.math.types.Vec2¶
- translate(offset: tuple[float, float] | numpy.ndarray)¶
- rotate(radians: float)¶
- rotate_deg(degrees: float)¶
- look_at(target: tuple[float, float] | numpy.ndarray)¶
- transform_points(points: list[simvx.core.math.types.Vec2]) → list[simvx.core.math.types.Vec2]¶
- draw_polygon(renderer, points: list[simvx.core.math.types.Vec2], closed=True, colour=None)¶
- wrap_screen(margin: float = 20)¶
- strict_errors: ClassVar[bool]¶
True
- script_error_raised¶
‘Signal(…)’
- classmethod __init_subclass__(**kwargs)¶
- property name: str¶
- property process_mode: simvx.core.descriptors.ProcessMode¶
- reset_error() → None¶
- add_child(node: simvx.core.node.Node) → simvx.core.node.Node¶
- remove_child(node: simvx.core.node.Node)¶
- reparent(new_parent: simvx.core.node.Node)¶
- get_node(path: str) → simvx.core.node.Node¶
- find_child(name: str, recursive: bool = False) → simvx.core.node.Node | None¶
- find(node_type: type, recursive: bool = True) → simvx.core.node.Node | None¶
- property path: str¶
- add_to_group(group: str)¶
- remove_from_group(group: str)¶
- is_in_group(group: str) → bool¶
- ready() → None¶
- enter_tree() → None¶
- exit_tree() → None¶
- process(dt: float) → None¶
- draw(renderer) → None¶
- input_event(event: simvx.core.events.InputEvent) → None¶
- input(event: simvx.core.events.TreeInputEvent) → None¶
- unhandled_input(event: simvx.core.events.TreeInputEvent) → None¶
- start_coroutine(gen: simvx.core.descriptors.Coroutine) → simvx.core.descriptors.CoroutineHandle¶
- stop_coroutine(gen_or_handle)¶
- clear_children()¶
- destroy()¶
- property app¶
- property tree: simvx.core.scene_tree.SceneTree¶
- get_tree() → simvx.core.scene_tree.SceneTree¶
- __getitem__(key: str)¶
- classmethod get_properties() → dict[str, simvx.core.descriptors.Property]¶
- __repr__()¶