I am trying to set a polygon’s collider through a script.
my code: borderCol.get("polygon").set(0, Vector2(1000, 1000))
borderCol.get("polygon").set(0, Vector2(1000, 1000))
but it doesn’t set the size.
polygon is a property of CollisionPolygon2D. As shown in the linked doc, its type is PoolVector2Array. This is an array of Vector2 objects representing the vertices of the polygon. For example to set a triangular shape, you need three points:
polygon
Vector2
var points = PoolVector2Array([Vector2(0, 0), Vector2(0, 100), Vector2(100, 100)]) borderCol.polygon = points
Note that in GDScript, there’s no need for get()/set() - you can just access the property directly to get or set the value.
get()/set()