This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+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 (22,191 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 Frequently asked questions and 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 [email protected] with your username.