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¶

属性¶

 float x `0.0` float y `0.0`

构造函数¶

 Vector2 Vector2() Vector2 Vector2(from: Vector2) Vector2 Vector2(from: Vector2i) Vector2 Vector2(x: float, y: float)

方法¶

 Vector2 abs() const float angle() const float angle_to(to: Vector2) const float angle_to_point(to: Vector2) const float aspect() const Vector2 bezier_derivative(control_1: Vector2, control_2: Vector2, end: Vector2, t: float) const Vector2 bezier_interpolate(control_1: Vector2, control_2: Vector2, end: Vector2, t: float) const Vector2 bounce(n: Vector2) const Vector2 ceil() const Vector2 clamp(min: Vector2, max: Vector2) const Vector2 clampf(min: float, max: float) const float cross(with: Vector2) const Vector2 cubic_interpolate(b: Vector2, pre_a: Vector2, post_b: Vector2, weight: float) const Vector2 cubic_interpolate_in_time(b: Vector2, pre_a: Vector2, post_b: Vector2, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const Vector2 direction_to(to: Vector2) const float distance_squared_to(to: Vector2) const float distance_to(to: Vector2) const float dot(with: Vector2) const Vector2 floor() const Vector2 from_angle(angle: float) static bool is_equal_approx(to: Vector2) const bool is_finite() const bool is_normalized() const bool is_zero_approx() const float length() const float length_squared() const Vector2 lerp(to: Vector2, weight: float) const Vector2 limit_length(length: float = 1.0) const Vector2 max(with: Vector2) const int max_axis_index() const Vector2 maxf(with: float) const Vector2 min(with: Vector2) const int min_axis_index() const Vector2 minf(with: float) const Vector2 move_toward(to: Vector2, delta: float) const Vector2 normalized() const Vector2 orthogonal() const Vector2 posmod(mod: float) const Vector2 posmodv(modv: Vector2) const Vector2 project(b: Vector2) const Vector2 reflect(line: Vector2) const Vector2 rotated(angle: float) const Vector2 round() const Vector2 sign() const Vector2 slerp(to: Vector2, weight: float) const Vector2 slide(n: Vector2) const Vector2 snapped(step: Vector2) const Vector2 snappedf(step: float) const

操作符¶

 bool operator !=(right: Vector2) Vector2 operator *(right: Transform2D) Vector2 operator *(right: Vector2) Vector2 operator *(right: float) Vector2 operator *(right: int) Vector2 operator +(right: Vector2) Vector2 operator -(right: Vector2) Vector2 operator /(right: Vector2) Vector2 operator /(right: float) Vector2 operator /(right: int) bool operator <(right: Vector2) bool operator <=(right: Vector2) bool operator ==(right: Vector2) bool operator >(right: Vector2) bool operator >=(right: Vector2) float operator [](index: int) Vector2 Vector2

常量¶

AXIS_X = `0` 🔗

X 轴的枚举值。由 max_axis_indexmin_axis_index 返回。

AXIS_Y = `1` 🔗

Y 轴的枚举值。由 max_axis_indexmin_axis_index 返回。

ZERO = `Vector2(0, 0)` 🔗

ONE = `Vector2(1, 1)` 🔗

INF = `Vector2(inf, inf)` 🔗

LEFT = `Vector2(-1, 0)` 🔗

RIGHT = `Vector2(1, 0)` 🔗

UP = `Vector2(0, -1)` 🔗

DOWN = `Vector2(0, 1)` 🔗

属性说明¶

float x = `0.0` 🔗

float y = `0.0` 🔗

构造函数说明¶

Vector2 Vector2() 🔗

Vector2 Vector2(from: Vector2)

Vector2 Vector2(from: Vector2i)

Vector2i 构造新的 Vector2

Vector2 Vector2(x: float, y: float)

方法说明¶

Vector2 abs() const 🔗

float angle() const 🔗

float angle_to(to: Vector2) const 🔗

float angle_to_point(to: Vector2) const 🔗

`a.angle_to_point(b)` 等价于 `(b - a).angle()`

float aspect() const 🔗

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

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

Vector2 bounce(n: Vector2) const 🔗

Returns the vector "bounced off" from a line defined by the given normal `n` perpendicular to the line.

Note: bounce performs the operation that most engines and frameworks call `reflect()`.

Vector2 ceil() const 🔗

Vector2 clamp(min: Vector2, max: Vector2) const 🔗

Vector2 clampf(min: float, max: float) const 🔗

Returns a new vector with all components clamped between `min` and `max`, by running @GlobalScope.clamp on each component.

float cross(with: Vector2) const 🔗

Returns the 2D analog of the cross product for this vector and `with`.

This is the signed area of the parallelogram formed by the two vectors. If the second vector is clockwise from the first vector, then the cross product is the positive area. If counter-clockwise, the cross product is the negative area. If the two vectors are parallel this returns zero, making it useful for testing if two vectors are parallel.

Note: Cross product is not defined in 2D mathematically. This method embeds the 2D vectors in the XY plane of 3D space and uses their cross product's Z component as the analog.

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

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

Vector2 direction_to(to: Vector2) const 🔗

float distance_squared_to(to: Vector2) const 🔗

float distance_to(to: Vector2) const 🔗

float dot(with: Vector2) const 🔗

Returns the dot product of this vector and `with`. This can be used to compare the angle between two vectors. For example, this can be used to determine whether an enemy is facing the player.

The dot product will be `0` for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees.

When using unit (normalized) vectors, the result will always be between `-1.0` (180 degree angle) when the vectors are facing