Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Vector2

使用浮点数坐标的 2D 向量。

Description

包含两个元素的结构体,可用于代表 2D 坐标或任何数值的二元组。

使用浮点数坐标。默认情况下,这些浮点值为 32 位精度,与始终为 64 位的 float 并不相同。如果需要双精度,请在编译引擎时使用 precision=double 选项。

对应的整数版本见 Vector2i

注意:在布尔语境中,如果 Vector2 等于 Vector2(0, 0) 则求值结果为 false。否则 Vector2 的求值结果始终为 true

Tutorials

Properties

float

x

0.0

float

y

0.0

Constructors

Vector2

Vector2 ( )

Vector2

Vector2 ( Vector2 from )

Vector2

Vector2 ( Vector2i from )

Vector2

Vector2 ( float x, float y )

Methods

Vector2

abs ( ) const

float

angle ( ) const

float

angle_to ( Vector2 to ) const

float

angle_to_point ( Vector2 to ) const

float

aspect ( ) const

Vector2

bezier_derivative ( Vector2 control_1, Vector2 control_2, Vector2 end, float t ) const

Vector2

bezier_interpolate ( Vector2 control_1, Vector2 control_2, Vector2 end, float t ) const

Vector2

bounce ( Vector2 n ) const

Vector2

ceil ( ) const

Vector2

clamp ( Vector2 min, Vector2 max ) const

float

cross ( Vector2 with ) const

Vector2

cubic_interpolate ( Vector2 b, Vector2 pre_a, Vector2 post_b, float weight ) const

Vector2

cubic_interpolate_in_time ( Vector2 b, Vector2 pre_a, Vector2 post_b, float weight, float b_t, float pre_a_t, float post_b_t ) const

Vector2

direction_to ( Vector2 to ) const

float

distance_squared_to ( Vector2 to ) const

float

distance_to ( Vector2 to ) const

float

dot ( Vector2 with ) const

Vector2

floor ( ) const

Vector2

from_angle ( float angle ) static

bool

is_equal_approx ( Vector2 to ) const

bool

is_finite ( ) const

bool

is_normalized ( ) const

bool

is_zero_approx ( ) const

float

length ( ) const

float

length_squared ( ) const

Vector2

lerp ( Vector2 to,