Correct Vector2Array Syntax

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BFGames
:warning: Old Version Published before Godot 3 was released.

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

:bust_in_silhouette: Reply From: Zylann

Apparently the doc still doesn’t show default constructors like I raised here Expose built-in types default constructors · Issue #6977 · godotengine/godot · GitHub

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.

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!

BFGames | 2017-12-05 17:11