virtualx-engine-docs/_sources/classes/class_vector2.rst.txt
2024-10-23 09:41:33 -07:00

717 lines
36 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Vector2.xml.
.. _class_Vector2:
Vector2
=======
Vector used for 2D math.
.. rst-class:: classref-introduction-group
Description
-----------
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``.
.. rst-class:: classref-introduction-group
Tutorials
---------
- :doc:`Math tutorial index <../tutorials/math/index>`
- :doc:`Vector math <../tutorials/math/vector_math>`
- :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
- `3Blue1Brown Essence of Linear Algebra <https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab>`__
- `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
- `All 2D Demos <https://github.com/godotengine/godot-demo-projects/tree/master/2d>`__
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+---------------------------+------------------------------------+---------+
| :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` | ``0.0`` |
+---------------------------+------------------------------------+---------+
| :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` | ``0.0`` |
+---------------------------+------------------------------------+---------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_method_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>` **(** :ref:`Vector2<class_Vector2>` to **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>` **(** :ref:`Vector2<class_Vector2>` n **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`clamped<class_Vector2_method_clamped>` **(** :ref:`float<class_float>` length **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>` **(** :ref:`Vector2<class_Vector2>` with **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`cubic_interpolate<class_Vector2_method_cubic_interpolate>` **(** :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` pre_a, :ref:`Vector2<class_Vector2>` post_b, :ref:`float<class_float>` weight **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>` **(** :ref:`Vector2<class_Vector2>` b **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>` **(** :ref:`Vector2<class_Vector2>` with **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` **(** :ref:`Vector2<class_Vector2>` v **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_zero_approx<class_Vector2_method_is_zero_approx>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>` **(** :ref:`float<class_float>` length=1.0 **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`linear_interpolate<class_Vector2_method_linear_interpolate>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>` **(** :ref:`float<class_float>` mod **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>` **(** :ref:`Vector2<class_Vector2>` modv **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` angle **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` by **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`tangent<class_Vector2_method_tangent>` **(** **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Constants
---------
.. _class_Vector2_constant_AXIS_X:
.. rst-class:: classref-constant
**AXIS_X** = ``0``
Enumerated value for the X axis.
.. _class_Vector2_constant_AXIS_Y:
.. rst-class:: classref-constant
**AXIS_Y** = ``1``
Enumerated value for the Y axis.
.. _class_Vector2_constant_ZERO:
.. rst-class:: classref-constant
**ZERO** = ``Vector2( 0, 0 )``
Zero vector, a vector with all components set to ``0``.
.. _class_Vector2_constant_ONE:
.. rst-class:: classref-constant
**ONE** = ``Vector2( 1, 1 )``
One vector, a vector with all components set to ``1``.
.. _class_Vector2_constant_INF:
.. rst-class:: classref-constant
**INF** = ``Vector2( inf, inf )``
Infinity vector, a vector with all components set to :ref:`@GDScript.INF<class_@GDScript_constant_INF>`.
.. _class_Vector2_constant_LEFT:
.. rst-class:: classref-constant
**LEFT** = ``Vector2( -1, 0 )``
Left unit vector. Represents the direction of left.
.. _class_Vector2_constant_RIGHT:
.. rst-class:: classref-constant
**RIGHT** = ``Vector2( 1, 0 )``
Right unit vector. Represents the direction of right.
.. _class_Vector2_constant_UP:
.. rst-class:: classref-constant
**UP** = ``Vector2( 0, -1 )``
Up unit vector. Y is down in 2D, so this vector points -Y.
.. _class_Vector2_constant_DOWN:
.. rst-class:: classref-constant
**DOWN** = ``Vector2( 0, 1 )``
Down unit vector. Y is down in 2D, so this vector points +Y.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_Vector2_property_x:
.. rst-class:: classref-property
:ref:`float<class_float>` **x** = ``0.0``
The vector's X component. Also accessible by using the index position ``[0]``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_property_y:
.. rst-class:: classref-property
:ref:`float<class_float>` **y** = ``0.0``
The vector's Y component. Also accessible by using the index position ``[1]``.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_Vector2_method_Vector2:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
Constructs a new Vector2 from the given ``x`` and ``y``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_abs:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **abs** **(** **)**
Returns a new vector with all components in absolute values (i.e. positive).
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_angle:
.. rst-class:: classref-method
:ref:`float<class_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. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png>`__\
Equivalent to the result of :ref:`@GDScript.atan2<class_@GDScript_method_atan2>` when called with the vector's :ref:`y<class_Vector2_property_y>` and :ref:`x<class_Vector2_property_x>` as parameters: ``atan2(y, x)``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_angle_to:
.. rst-class:: classref-method
:ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)**
Returns the angle to the given vector, in radians.
\ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png>`__
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_angle_to_point:
.. rst-class:: classref-method
:ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)**
Returns the angle between the line connecting the two points and the X axis, in radians.
\ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/3.6/img/vector2_angle_to_point.png>`__
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_aspect:
.. rst-class:: classref-method
:ref:`float<class_float>` **aspect** **(** **)**
Returns the aspect ratio of this vector, the ratio of :ref:`x<class_Vector2_property_x>` to :ref:`y<class_Vector2_property_y>`.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_bounce:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)**
Returns the vector "bounced off" from a plane defined by the given normal.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_ceil:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **ceil** **(** **)**
Returns a new vector with all components rounded up (towards positive infinity).
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_clamped:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
Deprecated, please use :ref:`limit_length<class_Vector2_method_limit_length>` instead.
Returns the vector with a maximum length by limiting its length to ``length``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_cross:
.. rst-class:: classref-method
:ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_cubic_interpolate:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **cubic_interpolate** **(** :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` pre_a, :ref:`Vector2<class_Vector2>` post_b, :ref:`float<class_float>` weight **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_direction_to:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` b **)**
Returns the normalized vector pointing from this vector to ``b``. This is equivalent to using ``(b - a).normalized()``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_distance_squared_to:
.. rst-class:: classref-method
:ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)**
Returns the squared distance between this vector and ``b``.
This method runs faster than :ref:`distance_to<class_Vector2_method_distance_to>`, so prefer it if you need to compare vectors or need the squared distance for some formula.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_distance_to:
.. rst-class:: classref-method
:ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)**
Returns the distance between this vector and ``to``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_dot:
.. rst-class:: classref-method
:ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)**
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 straight 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 opposite directions, and ``1.0`` (0 degree angle) when the vectors are aligned.
\ **Note:** ``a.dot(b)`` is equivalent to ``b.dot(a)``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_floor:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **floor** **(** **)**
Returns a new vector with all components rounded down (towards negative infinity).
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_is_equal_approx:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Vector2<class_Vector2>` v **)**
Returns ``true`` if this vector and ``v`` are approximately equal, by running :ref:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` on each component.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_is_normalized:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_normalized** **(** **)**
Returns ``true`` if the vector is normalized, ``false`` otherwise.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_is_zero_approx:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_zero_approx** **(** **)**
Returns ``true`` if this vector's values are approximately zero, by running :ref:`@GDScript.is_zero_approx<class_@GDScript_method_is_zero_approx>` on each component.
This method is faster than using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` with one value as a zero vector.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_length:
.. rst-class:: classref-method
:ref:`float<class_float>` **length** **(** **)**
Returns the length (magnitude) of this vector.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_length_squared:
.. rst-class:: classref-method
:ref:`float<class_float>` **length_squared** **(** **)**
Returns the squared length (squared magnitude) of this vector.
This method runs faster than :ref:`length<class_Vector2_method_length>`, so prefer it if you need to compare vectors or need the squared distance for some formula.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_limit_length:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **limit_length** **(** :ref:`float<class_float>` length=1.0 **)**
Returns the vector with a maximum length by limiting its length to ``length``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_linear_interpolate:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **linear_interpolate** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_move_toward:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)**
Returns a new vector moved toward ``to`` by the fixed ``delta`` amount. Will not go past the final value.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_normalized:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **normalized** **(** **)**
Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_posmod:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **posmod** **(** :ref:`float<class_float>` mod **)**
Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``mod``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_posmodv:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **posmodv** **(** :ref:`Vector2<class_Vector2>` modv **)**
Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``modv``'s components.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_project:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)**
Returns this vector projected onto the vector ``b``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_reflect:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)**
Returns the vector reflected (i.e. mirrored, or symmetric) over a line defined by the given direction vector ``n``.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_rotated:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` angle **)**
Returns the vector rotated by ``angle`` (in radians). See also :ref:`@GDScript.deg2rad<class_@GDScript_method_deg2rad>`.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_round:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **round** **(** **)**
Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_sign:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **sign** **(** **)**
Returns a new 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.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_slerp:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_slide:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)**
Returns this vector slid along a plane defined by the given normal.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_snapped:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` by **)**
Returns this vector with each component snapped to the nearest multiple of ``step``. This can also be used to round to an arbitrary number of decimals.
.. rst-class:: classref-item-separator
----
.. _class_Vector2_method_tangent:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **tangent** **(** **)**
Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`