0 votes

Hi,

I'm trying to change the shape of a collision polygon within the script, but I don't know how to set up a Vector2Array. I've had a look at the documentation, and the only parameter says Array from and I don't know where to begin without seeing an example usage.

Can anyone point me to an example or resource to use as a guide?

Thanks in advance

in Engine by (29 points)

1 Answer

+1 vote

Apparently the doc still doesn't show default constructors like I raised here https://github.com/godotengine/godot/issues/6977

In Godot 2.1, Vector2Array is created like this:

var a = Vector2Array()
a.append(Vector2(1,2))

It can also be created from a dynamic array, like the doc said shows:

var a = Vector2Array([ Vector2(1,1), Vector2(2, 2), Vector2(3,3) ])

Note: in Godot 3.0 Vector2Array has been renamed PoolVector2Array.

by (27,831 points)

I think it's a great point - from a relative newbie's perspective, having examples of the constructors would save no end of time - i've never encountered a Vector2Array in my limited experience and had no idea of the correct syntax. Never mind!

I'd attempted something like the dynamic array approach, but foolishly forgot the square brackets. Still not progressed to 3.0 yet, but thanks for the heads-up.

Appreciate the help - thanks!

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.