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

22 lines
561 B
GDScript
Raw Normal View History

2024-11-12 15:00:58 +01:00
class_name CNavigationPolygon
extends Node
var polygon: PackedVector2Array
var center_node: NavigationNode
func _init() -> void:
2024-11-21 18:32:27 +01:00
polygon = PackedVector2Array()
2024-11-12 15:00:58 +01:00
func set_polygon(new_polygon: PackedVector2Array) -> PackedVector2Array:
2024-11-21 18:32:27 +01:00
var new_polygon_clone: PackedVector2Array = new_polygon.duplicate()
new_polygon_clone.append(new_polygon_clone[0])
polygon = new_polygon_clone
return polygon
2024-11-12 15:00:58 +01:00
func center() -> Vector2:
2024-11-21 18:32:27 +01:00
var center: Vector2 = Vector2()
for point in polygon:
center += Vector2(point.x, point.y)
center /= polygon.size()
return center