gai-godot-games/pathfinding-algorithms/scenes/custom-solver/CNavigationPolygon.gd

22 lines
594 B
GDScript

class_name CNavigationPolygon
extends Node
var polygon: PackedVector2Array
var center_node: NavigationNode
func _init() -> void:
polygon = PackedVector2Array()
func set_polygon(new_polygon: PackedVector2Array) -> PackedVector2Array:
var new_polygon_clone: PackedVector2Array = new_polygon.duplicate()
new_polygon_clone.append(new_polygon_clone[0])
polygon = new_polygon_clone
return polygon
func center() -> Vector2:
var center: Vector2 = Vector2()
for point in polygon:
center += Vector2(point.x, point.y)
center /= polygon.size()
return center