+1 vote

I am trying to set a polygon's collider through a script.

my code:
borderCol.get("polygon").set(0, Vector2(1000, 1000))

but it doesn't set the size.

in Engine by (13 points)

1 Answer

+1 vote

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:

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.

by (20,475 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.