123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750 |
- :github_url: hide
- .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
- .. DO NOT EDIT THIS FILE, but the Vector2.xml source instead.
- .. The source is found in doc/classes or modules/<name>/doc_classes.
- .. _class_Vector2:
- Vector2
- =======
- Vector used for 2D math using floating point coordinates.
- Description
- -----------
- 2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.
- It uses floating-point coordinates. See :ref:`Vector2i<class_Vector2i>` for its integer counterpart.
- **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``.
- Tutorials
- ---------
- - :doc:`Math documentation 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>`__
- Properties
- ----------
- +---------------------------+------------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` | ``0.0`` |
- +---------------------------+------------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` | ``0.0`` |
- +---------------------------+------------------------------------+---------+
- Constructors
- ------------
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`Vector2<class_Vector2>` from **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`Vector2i<class_Vector2i>` from **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
- Methods
- -------
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`clamp<class_Vector2_method_clamp>` **(** :ref:`Vector2<class_Vector2>` min, :ref:`Vector2<class_Vector2>` max **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>` **(** :ref:`Vector2<class_Vector2>` with **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :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 **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>` **(** :ref:`Vector2<class_Vector2>` b **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>` **(** :ref:`Vector2<class_Vector2>` with **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`from_angle<class_Vector2_method_from_angle>` **(** :ref:`float<class_float>` angle **)** |static| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`lerp<class_Vector2_method_lerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>` **(** :ref:`float<class_float>` length=1.0 **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`orthogonal<class_Vector2_method_orthogonal>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>` **(** :ref:`float<class_float>` mod **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>` **(** :ref:`Vector2<class_Vector2>` modv **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` phi **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>` **(** **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` step **)** |const| |
- +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Operators
- ---------
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator !=<class_Vector2_operator_neq_bool>` **(** **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator !=<class_Vector2_operator_neq_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>` **(** :ref:`Transform2D<class_Transform2D>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>` **(** :ref:`float<class_float>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>` **(** :ref:`int<class_int>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator +<class_Vector2_operator_sum_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator -<class_Vector2_operator_dif_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_Vector2>` **(** :ref:`float<class_float>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_Vector2>` **(** :ref:`int<class_int>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator <<class_Vector2_operator_lt_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator <=<class_Vector2_operator_lte_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator ==<class_Vector2_operator_eq_bool>` **(** **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator ==<class_Vector2_operator_eq_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator ><class_Vector2_operator_gt_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator >=<class_Vector2_operator_gte_bool>` **(** :ref:`Vector2<class_Vector2>` right **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`operator []<class_Vector2_operator_idx_float>` **(** :ref:`int<class_int>` index **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator unary+<class_Vector2_operator_unplus_Vector2>` **(** **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`operator unary-<class_Vector2_operator_unminus_Vector2>` **(** **)** |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------+
- Constants
- ---------
- .. _class_Vector2_constant_AXIS_X:
- .. _class_Vector2_constant_AXIS_Y:
- .. _class_Vector2_constant_ZERO:
- .. _class_Vector2_constant_ONE:
- .. _class_Vector2_constant_INF:
- .. _class_Vector2_constant_LEFT:
- .. _class_Vector2_constant_RIGHT:
- .. _class_Vector2_constant_UP:
- .. _class_Vector2_constant_DOWN:
- - **AXIS_X** = **0** --- Enumerated value for the X axis.
- - **AXIS_Y** = **1** --- Enumerated value for the Y axis.
- - **ZERO** = **Vector2(0, 0)** --- Zero vector, a vector with all components set to ``0``.
- - **ONE** = **Vector2(1, 1)** --- One vector, a vector with all components set to ``1``.
- - **INF** = **Vector2(inf, inf)** --- Infinity vector, a vector with all components set to :ref:`@GDScript.INF<class_@GDScript_constant_INF>`.
- - **LEFT** = **Vector2(-1, 0)** --- Left unit vector. Represents the direction of left.
- - **RIGHT** = **Vector2(1, 0)** --- Right unit vector. Represents the direction of right.
- - **UP** = **Vector2(0, -1)** --- Up unit vector. Y is down in 2D, so this vector points -Y.
- - **DOWN** = **Vector2(0, 1)** --- Down unit vector. Y is down in 2D, so this vector points +Y.
- Property Descriptions
- ---------------------
- .. _class_Vector2_property_x:
- - :ref:`float<class_float>` **x**
- +-----------+---------+
- | *Default* | ``0.0`` |
- +-----------+---------+
- The vector's X component. Also accessible by using the index position ``[0]``.
- ----
- .. _class_Vector2_property_y:
- - :ref:`float<class_float>` **y**
- +-----------+---------+
- | *Default* | ``0.0`` |
- +-----------+---------+
- The vector's Y component. Also accessible by using the index position ``[1]``.
- Constructor Descriptions
- ------------------------
- .. _class_Vector2_constructor_Vector2:
- - :ref:`Vector2<class_Vector2>` **Vector2** **(** **)**
- Constructs a default-initialized ``Vector2`` with all components set to ``0``.
- ----
- - :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`Vector2<class_Vector2>` from **)**
- Constructs a ``Vector2`` as a copy of the given ``Vector2``.
- ----
- - :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`Vector2i<class_Vector2i>` from **)**
- Constructs a new ``Vector2`` from :ref:`Vector2i<class_Vector2i>`.
- ----
- - :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``.
- Method Descriptions
- -------------------
- .. _class_Vector2_method_abs:
- - :ref:`Vector2<class_Vector2>` **abs** **(** **)** |const|
- Returns a new vector with all components in absolute values (i.e. positive).
- ----
- .. _class_Vector2_method_angle:
- - :ref:`float<class_float>` **angle** **(** **)** |const|
- 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:`@GlobalScope.atan2<class_@GlobalScope_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)``.
- ----
- .. _class_Vector2_method_angle_to:
- - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
- 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>`__
- ----
- .. _class_Vector2_method_angle_to_point:
- - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
- Returns the angle between the line connecting the two points and the X axis, in radians.
- ``a.angle_to_point(b)`` is equivalent of doing ``(b - a).angle()``.
- `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to_point.png>`__
- ----
- .. _class_Vector2_method_aspect:
- - :ref:`float<class_float>` **aspect** **(** **)** |const|
- Returns the aspect ratio of this vector, the ratio of :ref:`x<class_Vector2_property_x>` to :ref:`y<class_Vector2_property_y>`.
- ----
- .. _class_Vector2_method_bounce:
- - :ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
- Returns the vector "bounced off" from a plane defined by the given normal.
- ----
- .. _class_Vector2_method_ceil:
- - :ref:`Vector2<class_Vector2>` **ceil** **(** **)** |const|
- Returns the vector with all components rounded up (towards positive infinity).
- ----
- .. _class_Vector2_method_clamp:
- - :ref:`Vector2<class_Vector2>` **clamp** **(** :ref:`Vector2<class_Vector2>` min, :ref:`Vector2<class_Vector2>` max **)** |const|
- Returns a new vector with all components clamped between the components of ``min`` and ``max``, by running :ref:`@GlobalScope.clamp<class_@GlobalScope_method_clamp>` on each component.
- ----
- .. _class_Vector2_method_cross:
- - :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)** |const|
- Returns the cross product of this vector and ``with``.
- ----
- .. _class_Vector2_method_cubic_interpolate:
- - :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 **)** |const|
- 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.
- ----
- .. _class_Vector2_method_direction_to:
- - :ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` b **)** |const|
- Returns the normalized vector pointing from this vector to ``b``. This is equivalent to using ``(b - a).normalized()``.
- ----
- .. _class_Vector2_method_distance_squared_to:
- - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
- 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.
- ----
- .. _class_Vector2_method_distance_to:
- - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
- Returns the distance between this vector and ``to``.
- ----
- .. _class_Vector2_method_dot:
- - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)** |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 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)``.
- ----
- .. _class_Vector2_method_floor:
- - :ref:`Vector2<class_Vector2>` **floor** **(** **)** |const|
- Returns the vector with all components rounded down (towards negative infinity).
- ----
- .. _class_Vector2_method_from_angle:
- - :ref:`Vector2<class_Vector2>` **from_angle** **(** :ref:`float<class_float>` angle **)** |static|
- Creates a unit ``Vector2`` rotated to the given ``angle`` in radians. This is equivalent to doing ``Vector2(cos(angle), sin(angle))`` or ``Vector2.RIGHT.rotated(angle)``.
- ::
- print(Vector2.from_angle(0)) # Prints (1, 0).
- print(Vector2(1, 0).angle()) # Prints 0, which is the angle used above.
- print(Vector2.from_angle(PI / 2)) # Prints (0, 1).
- ----
- .. _class_Vector2_method_is_equal_approx:
- - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
- Returns ``true`` if this vector and ``v`` are approximately equal, by running :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on each component.
- ----
- .. _class_Vector2_method_is_normalized:
- - :ref:`bool<class_bool>` **is_normalized** **(** **)** |const|
- Returns ``true`` if the vector is normalized, ``false`` otherwise.
- ----
- .. _class_Vector2_method_length:
- - :ref:`float<class_float>` **length** **(** **)** |const|
- Returns the length (magnitude) of this vector.
- ----
- .. _class_Vector2_method_length_squared:
- - :ref:`float<class_float>` **length_squared** **(** **)** |const|
- 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.
- ----
- .. _class_Vector2_method_lerp:
- - :ref:`Vector2<class_Vector2>` **lerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const|
- 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.
- ----
- .. _class_Vector2_method_limit_length:
- - :ref:`Vector2<class_Vector2>` **limit_length** **(** :ref:`float<class_float>` length=1.0 **)** |const|
- Returns the vector with a maximum length by limiting its length to ``length``.
- ----
- .. _class_Vector2_method_move_toward:
- - :ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |const|
- Moves the vector toward ``to`` by the fixed ``delta`` amount.
- ----
- .. _class_Vector2_method_normalized:
- - :ref:`Vector2<class_Vector2>` **normalized** **(** **)** |const|
- Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
- ----
- .. _class_Vector2_method_orthogonal:
- - :ref:`Vector2<class_Vector2>` **orthogonal** **(** **)** |const|
- Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
- ----
- .. _class_Vector2_method_posmod:
- - :ref:`Vector2<class_Vector2>` **posmod** **(** :ref:`float<class_float>` mod **)** |const|
- Returns a vector composed of the :ref:`@GlobalScope.fposmod<class_@GlobalScope_method_fposmod>` of this vector's components and ``mod``.
- ----
- .. _class_Vector2_method_posmodv:
- - :ref:`Vector2<class_Vector2>` **posmodv** **(** :ref:`Vector2<class_Vector2>` modv **)** |const|
- Returns a vector composed of the :ref:`@GlobalScope.fposmod<class_@GlobalScope_method_fposmod>` of this vector's components and ``modv``'s components.
- ----
- .. _class_Vector2_method_project:
- - :ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)** |const|
- Returns the vector projected onto the vector ``b``.
- ----
- .. _class_Vector2_method_reflect:
- - :ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
- Returns the vector reflected from a plane defined by the given normal.
- ----
- .. _class_Vector2_method_rotated:
- - :ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` phi **)** |const|
- Returns the vector rotated by ``phi`` radians. See also :ref:`@GlobalScope.deg2rad<class_@GlobalScope_method_deg2rad>`.
- ----
- .. _class_Vector2_method_round:
- - :ref:`Vector2<class_Vector2>` **round** **(** **)** |const|
- Returns the vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
- ----
- .. _class_Vector2_method_sign:
- - :ref:`Vector2<class_Vector2>` **sign** **(** **)** |const|
- Returns the vector with each component set to one or negative one, depending on the signs of the components, or zero if the component is zero, by calling :ref:`@GlobalScope.sign<class_@GlobalScope_method_sign>` on each component.
- ----
- .. _class_Vector2_method_slerp:
- - :ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const|
- 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.
- ----
- .. _class_Vector2_method_slide:
- - :ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
- Returns this vector slid along a plane defined by the given normal.
- ----
- .. _class_Vector2_method_snapped:
- - :ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` step **)** |const|
- 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.
- Operator Descriptions
- ---------------------
- .. _class_Vector2_operator_neq_bool:
- - :ref:`bool<class_bool>` **operator !=** **(** **)**
- ----
- - :ref:`bool<class_bool>` **operator !=** **(** :ref:`Vector2<class_Vector2>` right **)**
- Returns ``true`` if the vectors are not equal.
- **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` instead, which is more reliable.
- ----
- .. _class_Vector2_operator_mul_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Vector2<class_Vector2>` right **)**
- Multiplies each component of the ``Vector2`` by the components of the given ``Vector2``.
- ::
- print(Vector2(10, 20) * Vector2(3, 4)) # Prints "(30, 80)"
- ----
- - :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Transform2D<class_Transform2D>` right **)**
- Inversely transforms (multiplies) the ``Vector2`` by the given :ref:`Transform2D<class_Transform2D>` transformation matrix.
- ----
- - :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`float<class_float>` right **)**
- Multiplies each component of the ``Vector2`` by the given :ref:`float<class_float>`.
- ----
- - :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`int<class_int>` right **)**
- Multiplies each component of the ``Vector2`` by the given :ref:`int<class_int>`.
- ----
- .. _class_Vector2_operator_sum_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator +** **(** :ref:`Vector2<class_Vector2>` right **)**
- Adds each component of the ``Vector2`` by the components of the given ``Vector2``.
- ::
- print(Vector2(10, 20) + Vector2(3, 4)) # Prints "(13, 24)"
- ----
- .. _class_Vector2_operator_dif_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator -** **(** :ref:`Vector2<class_Vector2>` right **)**
- Subtracts each component of the ``Vector2`` by the components of the given ``Vector2``.
- ::
- print(Vector2(10, 20) - Vector2(3, 4)) # Prints "(7, 16)"
- ----
- .. _class_Vector2_operator_div_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`Vector2<class_Vector2>` right **)**
- Divides each component of the ``Vector2`` by the components of the given ``Vector2``.
- ::
- print(Vector2(10, 20) / Vector2(2, 5)) # Prints "(5, 4)"
- ----
- - :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`float<class_float>` right **)**
- Divides each component of the ``Vector2`` by the given :ref:`float<class_float>`.
- ----
- - :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`int<class_int>` right **)**
- Divides each component of the ``Vector2`` by the given :ref:`int<class_int>`.
- ----
- .. _class_Vector2_operator_lt_bool:
- - :ref:`bool<class_bool>` **operator <** **(** :ref:`Vector2<class_Vector2>` right **)**
- Compares two ``Vector2`` vectors by first checking if the X value of the left vector is less than the X value of the ``right`` vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
- ----
- .. _class_Vector2_operator_lte_bool:
- - :ref:`bool<class_bool>` **operator <=** **(** :ref:`Vector2<class_Vector2>` right **)**
- Compares two ``Vector2`` vectors by first checking if the X value of the left vector is less than or equal to the X value of the ``right`` vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
- ----
- .. _class_Vector2_operator_eq_bool:
- - :ref:`bool<class_bool>` **operator ==** **(** **)**
- ----
- - :ref:`bool<class_bool>` **operator ==** **(** :ref:`Vector2<class_Vector2>` right **)**
- Returns ``true`` if the vectors are exactly equal.
- **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` instead, which is more reliable.
- ----
- .. _class_Vector2_operator_gt_bool:
- - :ref:`bool<class_bool>` **operator >** **(** :ref:`Vector2<class_Vector2>` right **)**
- Compares two ``Vector2`` vectors by first checking if the X value of the left vector is greater than the X value of the ``right`` vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
- ----
- .. _class_Vector2_operator_gte_bool:
- - :ref:`bool<class_bool>` **operator >=** **(** :ref:`Vector2<class_Vector2>` right **)**
- Compares two ``Vector2`` vectors by first checking if the X value of the left vector is greater than or equal to the X value of the ``right`` vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
- ----
- .. _class_Vector2_operator_idx_float:
- - :ref:`float<class_float>` **operator []** **(** :ref:`int<class_int>` index **)**
- Access vector components using their index. ``v[0]`` is equivalent to ``v.x``, and ``v[1]`` is equivalent to ``v.y``.
- ----
- .. _class_Vector2_operator_unplus_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator unary+** **(** **)**
- Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
- ----
- .. _class_Vector2_operator_unminus_Vector2:
- - :ref:`Vector2<class_Vector2>` **operator unary-** **(** **)**
- Returns the negative value of the ``Vector2``. This is the same as writing ``Vector2(-v.x, -v.y)``. This operation flips the direction of the vector while keeping the same magnitude. With floats, the number zero can be either positive or negative.
- .. |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.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|