Vector2

Vector used for 2D math.

Descripción

2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.

Note: In a boolean context, a Vector2 will evaluate to false if it's equal to Vector2(0, 0). Otherwise, a Vector2 will always evaluate to true.

Tutoriales

Propiedades

float

x

0.0

float

y

0.0

Métodos

Vector2

Vector2 ( float x, float y )

Vector2

abs ( )

float

angle ( )

float

angle_to ( Vector2 to )

float

angle_to_point ( Vector2 to )

float

aspect ( )

Vector2

bounce ( Vector2 n )

Vector2

ceil ( )

Vector2

clamped ( float length )

float

cross ( Vector2 with )

Vector2

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

Vector2

direction_to ( Vector2 b )

float

distance_squared_to ( Vector2 to )

float

distance_to ( Vector2 to )

float

dot ( Vector2 with )

Vector2

floor ( )

bool

is_equal_approx ( Vector2 v )

bool

is_normalized ( )

float

length ( )

float

length_squared ( )

Vector2

limit_length ( float length=1.0 )

Vector2

linear_interpolate ( Vector2 to, float weight )

Vector2

move_toward ( Vector2 to, float delta )

Vector2

normalized ( )

Vector2

posmod ( float mod )

Vector2

posmodv ( Vector2 modv )

Vector2

project ( Vector2 b )

Vector2

reflect ( Vector2 n )

Vector2

rotated ( float phi )

Vector2

round ( )

Vector2

sign ( )

Vector2

slerp ( Vector2 to, float weight )

Vector2

slide ( Vector2 n )

Vector2

snapped ( Vector2 by )

Vector2

tangent ( )

Constantes

  • AXIS_X = 0 --- Valor enumerado para el eje X.

  • AXIS_Y = 1 --- Valor enumerado para el eje Y.

  • ZERO = Vector2( 0, 0 ) --- Vector cero, un vector con todos los componentes ajustados a 0.

  • ONE = Vector2( 1, 1 ) --- Un vector, un vector con todos los componentes ajustados a 1.

  • INF = Vector2( inf, inf ) --- Vector infinito, un vector con todos los componentes ajustados a @GDScript.INF.

  • LEFT = Vector2( -1, 0 ) --- Vector de la unidad izquierda. Representa la dirección de la izquierda.

  • RIGHT = Vector2( 1, 0 ) --- Vector de la unidad derecha. Representa la dirección de la derecha.

  • UP = Vector2( 0, -1 ) --- Vector de la unidad superior. Y está abajo en 2D, por lo que este vector apunta -Y.

  • DOWN = Vector2( 0, 1 ) --- Vector de la unidad de descenso. Y está abajo en 2D, así que este vector apunta a +Y.

Descripciones de Propiedades

Default

0.0

El componente X del vector. También se puede acceder utilizando la posición del índice [0].


Default

0.0

El componente Y del vector. También se puede acceder usando la posición del índice [1].

Descripciones de Métodos

Constructs a new Vector2 from the given x and y.


Devuelve un nuevo vector con todos los componentes en valores absolutos (es decir, positivos).


Returns this vector's angle with respect to the positive X axis, or (1, 0) vector, in radians.

For example, Vector2.RIGHT.angle() will return zero, Vector2.DOWN.angle() will return PI / 2 (a quarter turn, or 90 degrees), and Vector2(1, -1).angle() will return -PI / 4 (a negative eighth turn, or -45 degrees).

Illustration of the returned angle.

Equivalent to the result of @GDScript.atan2 when called with the vector's y and x as parameters: atan2(y, x).


Returns the angle to the given vector, in radians.

Illustration of the returned angle.


Returns the angle between the line connecting the two points and the X axis, in radians.

Illustration of the returned angle.


Devuelve la relación de aspecto de este vector, la relación de x a y.


Devuelve el vector "rebotado" de un plano definido por la normalidad dada.


Devuelve el vector con todos los componentes redondeados hacia arriba (hacia el infinito positivo).


Deprecated, please use limit_length instead.

Returns the vector with a maximum length by limiting its length to length.


Devuelve el producto cruzado de este vector y with.


Cubically interpolates between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.


Returns the normalized vector pointing from this vector to b. This is equivalent to using (b - a).normalized().


Devuelve la distancia cuadrada entre este vector y b.

Este método funciona más rápido que el distance_to, por lo que es preferible si necesitas comparar vectores o necesitas la distancia al cuadrado para alguna fórmula.


Devuelve la distancia entre este vector y to.


Devuelve el producto escalar de este vector y with. Esto puede ser usado para comparar el ángulo entre dos vectores. Por ejemplo, esto puede ser usado para determinar si un enemigo está de cara al jugador.

El producto escalar será 0 para un ángulo recto (90 grados), mayor que 0 para ángulos más estrechos que 90 grados y menor que 0 para ángulos más anchos que 90 grados.

Cuando se utilizan vectores unitarios (normalizados), el resultado siempre estará entre -1.0 (ángulo de 180 grados) cuando los vectores estén orientados en direcciones opuestas, y 1.0 (ángulo de 0 grados) cuando los vectores estén alineados.

**Nota: ** a.dot(b) es equivalente a b.dot(a).


Devuelve el vector con todos los componentes redondeados hacia abajo (hacia el infinito negativo).


Devuelve true si este vector y v son aproximadamente iguales, ejecutando @GDScript.is_equal_approx en cada componente.


  • bool is_normalized ( )

Returns true if the vector is normalized, false otherwise.


Devuelve la longitud (magnitud) de este vector.


  • float length_squared ( )

Devuelve la longitud cuadrada (magnitud cuadrada) de este vector.

Este método funciona más rápido que el length, por lo que es preferible si necesitas comparar vectores o necesitas la distancia al cuadrado para alguna fórmula.


Devuelve el vector con una longitud máxima limitando su longitud a length.


Returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.


Mueve el vector hacia a por la cantidad fija de delta.


Devuelve el vector escalado a la longitud de la unidad. Equivalente a v / v.length().


Devuelve un vector compuesto por el @GDScript.fposmod de los componentes de este vector y el mod.


Devuelve un vector compuesto por el @GDScript.fposmod de los componentes de este vector y los componentes del modv.


Devuelve el vector proyectado sobre el vector b.


Devuelve el vector reflejado desde un plano definido por la normal dada.


Devuelve el vector rotado por phi radianes. Ver también @GDScript.deg2rad.


Devuelve el vector con todos los componentes redondeados al entero más cercano, con los casos intermedios redondeados desde cero.


Returns the vector with each component set to one or negative one, depending on the signs of the components. If a component is zero, it returns positive one.


Returns the result of spherical linear interpolation between this vector and to, by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

Note: Both vectors must be normalized.


Devuelve este vector deslizado a lo largo de un plano definido por la normalidad dada.


Devuelve este vector con cada componente ajustado al múltiplo más cercano de step. Esto también puede ser usado para redondear a un número arbitrario de decimales.


Devuelve un vector perpendicular girado 90 grados en sentido contrario a las agujas del reloj en comparación con el original, con la misma longitud.