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¶
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)¶
Add a point to the graph. Weight scales traversal cost (default 1.0).
- remove_point(id: int)¶
Remove a point and all its connections.
- connect_points(id1: int, id2: int, bidirectional: bool = True)¶
Connect two points. Both must already exist.
- disconnect_points(id1: int, id2: int, bidirectional: bool = True)¶
Remove connection between two points.
- set_point_disabled(id: int, disabled: bool = True)¶
Disable/enable a point. Disabled points are excluded from pathfinding.
- is_point_disabled(id: int) → bool¶
- has_point(id: int) → bool¶
- get_point_position(id: int) → tuple[float, float]¶
- get_point_connections(id: int) → set[int]¶
- get_point_count() → int¶
- get_closest_point(position: tuple[float, float]) → int¶
Return id of the closest non-disabled point to the given position.
- get_id_path(from_id: int, to_id: int) → list[int]¶
A* search returning list of point IDs from start to end. Empty list if no path.
- get_point_path(from_id: int, to_id: int) → list[tuple[float, float]]¶
A* search returning list of world positions.
- 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))¶
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)¶
Mark a cell as solid (impassable) or clear it.
- is_solid(x: int, y: int) → bool¶
- set_weight(x: int, y: int, weight: float)¶
Set traversal weight for a cell. Default is 1.0; higher = costlier.
- find_path(from_cell: tuple[int, int], to_cell: tuple[int, int]) → list[tuple[int, int]]¶
Find shortest path between two grid cells. Returns list of (x,y) cells.
- find_path_world(from_pos: tuple[float, float], to_pos: tuple[float, float]) → list[tuple[float, float]]¶
Find path using world positions (auto-converts to/from grid coords).
- class simvx.core.navigation.NavigationAgent2D(max_speed: float = 100.0, path_desired_distance: float = 4.0, **kwargs)¶
Bases:
simvx.core.engine.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)¶
Assign a pathfinder instance.
- physics_process(dt: float)¶
- z_index¶
‘Property(…)’
- z_as_relative¶
‘Property(…)’
- 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 global_position: simvx.core.math.types.Vec2¶
- property global_rotation: float¶
- property global_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, color=None)¶
- wrap_screen(margin: float = 20)¶
- 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) → 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)¶
- destroy()¶
- queue_free¶
None
- 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]¶
- get_settings¶
None
- __repr__()¶