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¶
|
||
|
Métodos¶
abs ( ) |
|
angle ( ) |
|
angle_to_point ( Vector2 to ) |
|
aspect ( ) |
|
ceil ( ) |
|
cubic_interpolate ( Vector2 b, Vector2 pre_a, Vector2 post_b, float weight ) |
|
direction_to ( Vector2 b ) |
|
distance_squared_to ( Vector2 to ) |
|
distance_to ( Vector2 to ) |
|
floor ( ) |
|
is_equal_approx ( Vector2 v ) |
|
is_normalized ( ) |
|
length ( ) |
|
length_squared ( ) |
|
limit_length ( float length=1.0 ) |
|
linear_interpolate ( Vector2 to, float weight ) |
|
move_toward ( Vector2 to, float delta ) |
|
normalized ( ) |
|
round ( ) |
|
sign ( ) |
|
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¶
float x
Default |
|
El componente X del vector. También se puede acceder utilizando la posición del índice [0]
.
float y
Default |
|
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
.
Vector2 abs ( )
Devuelve un nuevo vector con todos los componentes en valores absolutos (es decir, positivos).
float angle ( )
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.
float aspect ( )
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.
Vector2 ceil ( )
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)
.
Vector2 floor ( )
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.
float length ( )
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
.
Vector2 normalized ( )
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.
Vector2 round ( )
Devuelve el vector con todos los componentes redondeados al entero más cercano, con los casos intermedios redondeados desde cero.
Vector2 sign ( )
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.
Vector2 tangent ( )
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.