Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | panderbeers |
Hello there - beginner here, and I thank you in advance for the help.
I’m working on cutting out polygons from a NavigationPolygonInstance, and I’m trying to make a multiuse() function out of the singleuse() function from this tutorial: https://www.youtube.com/watch?v=uzqRjEoBcTI
I’ve tagged my KinematicBody2D nodes as “Defenders” and they are in a YSort and I have the following script attached to my Navigation2D on the same level as the YSort.
I get all of the nodes grouped as “Defenders” and put them into my DefendersOnField array. I then pass that array into my multiuse(array) function.
Now my problem is the get_polygon() function on the line
var polygon_bp = DefenderNodes[i].CollisionPolygon2D.get_polygon()
I’m guessing that’s not how I’m supposed to get the child of the node I’m working on, but I am not sure.
The error I’m getting on that line is "Invalid get index ‘CollisionPolygon2D’ (on base: ‘KinematicBody2D (Entity-Defender.gd)’).
extends Navigation2D
func _ready():
var DefendersOnField = get_tree().get_nodes_in_group("Defenders")
multiuse(DefendersOnField)
func multiuse(array):
var DefenderNodes = array
for i in DefenderNodes.size():
var newpolygon = PoolVector2Array()
var polygon = $NavigationPolygonInstance.get_navigation_polygon()
var polygon_transform = DefenderNodes[i].CollisionPolygon2D.get_global_transform()
var polygon_bp = DefenderNodes[i].CollisionPolygon2D.get_polygon()
for vertex in polygon_bp:
newpolygon.append(polygon_transform.xform(vertex))
polygon.add_outline(newpolygon)
polygon.make_polygons_from_outlines()
$NavigationPolygonInstance.set_navigation_polygon(polygon)
var navPolyInstance = $NavigationPolygonInstance
navPolyInstance.enabled = false
navPolyInstance.enabled = true