Skip to content

PolygonPathFinder

Inherits: Resource < RefCounted < Object

Returns Method
PackedVector2Array find_path(from: Vector2, to: Vector2)
Rect2 get_bounds() const
Vector2 get_closest_point(point: Vector2) const
PackedVector2Array get_intersections(from: Vector2, to: Vector2) const
float get_point_penalty(idx: int) const
bool is_point_inside(point: Vector2) const
void set_point_penalty(idx: int, penalty: float)
void setup(points: PackedVector2Array, connections: PackedInt32Array)

find_path

PackedVector2Array find_path(from: Vector2, to: Vector2)

get_bounds

Rect2 get_bounds() const

get_closest_point

Vector2 get_closest_point(point: Vector2) const

get_intersections

PackedVector2Array get_intersections(from: Vector2, to: Vector2) const

get_point_penalty

float get_point_penalty(idx: int) const

is_point_inside

bool is_point_inside(point: Vector2) const

Returns true if point falls inside the polygon area.

var polygonPathFinder = new PolygonPathFinder();
Vector2[] points =
[
new Vector2(0.0f, 0.0f),
new Vector2(1.0f, 0.0f),
new Vector2(0.0f, 1.0f)
];
int[] connections = [0, 1, 1, 2, 2, 0];
polygonPathFinder.Setup(points, connections);
Orb.Print(polygonPathFinder.IsPointInside(new Vector2(0.2f, 0.2f))); // Prints True
Orb.Print(polygonPathFinder.IsPointInside(new Vector2(1.0f, 1.0f))); // Prints False

set_point_penalty

void set_point_penalty(idx: int, penalty: float)

setup

void setup(points: PackedVector2Array, connections: PackedInt32Array)

Sets up PolygonPathFinder with an array of points that define the vertices of the polygon, and an array of indices that determine the edges of the polygon.

The length of connections must be even, returns an error if odd.

var polygonPathFinder = new PolygonPathFinder();
Vector2[] points =
[
new Vector2(0.0f, 0.0f),
new Vector2(1.0f, 0.0f),
new Vector2(0.0f, 1.0f)
];
int[] connections = [0, 1, 1, 2, 2, 0];
polygonPathFinder.Setup(points, connections);