class_vector2.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Vector2.xml.
  6. .. _class_Vector2:
  7. Vector2
  8. =======
  9. Vector used for 2D math.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. 2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.
  14. \ **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``.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`Math tutorial index <../tutorials/math/index>`
  19. - :doc:`Vector math <../tutorials/math/vector_math>`
  20. - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
  21. - `3Blue1Brown Essence of Linear Algebra <https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab>`__
  22. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  23. - `All 2D Demos <https://github.com/godotengine/godot-demo-projects/tree/master/2d>`__
  24. .. rst-class:: classref-reftable-group
  25. Properties
  26. ----------
  27. .. table::
  28. :widths: auto
  29. +---------------------------+------------------------------------+---------+
  30. | :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` | ``0.0`` |
  31. +---------------------------+------------------------------------+---------+
  32. | :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` | ``0.0`` |
  33. +---------------------------+------------------------------------+---------+
  34. .. rst-class:: classref-reftable-group
  35. Methods
  36. -------
  37. .. table::
  38. :widths: auto
  39. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_method_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  41. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>` **(** **)** |
  43. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>` **(** **)** |
  45. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  47. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  49. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>` **(** **)** |
  51. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  53. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>` **(** **)** |
  55. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Vector2<class_Vector2>` | :ref:`clamped<class_Vector2_method_clamped>` **(** :ref:`float<class_float>` length **)** |
  57. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>` **(** :ref:`Vector2<class_Vector2>` with **)** |
  59. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :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 **)** |
  61. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>` **(** :ref:`Vector2<class_Vector2>` b **)** |
  63. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  65. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  67. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>` **(** :ref:`Vector2<class_Vector2>` with **)** |
  69. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>` **(** **)** |
  71. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  73. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>` **(** **)** |
  75. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`is_zero_approx<class_Vector2_method_is_zero_approx>` **(** **)** |
  77. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |
  79. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |
  81. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>` **(** :ref:`float<class_float>` length=1.0 **)** |
  83. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector2<class_Vector2>` | :ref:`linear_interpolate<class_Vector2_method_linear_interpolate>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
  85. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |
  87. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |
  89. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>` **(** :ref:`float<class_float>` mod **)** |
  91. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>` **(** :ref:`Vector2<class_Vector2>` modv **)** |
  93. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |
  95. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  97. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` angle **)** |
  99. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |
  101. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>` **(** **)** |
  103. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
  105. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  107. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` by **)** |
  109. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`Vector2<class_Vector2>` | :ref:`tangent<class_Vector2_method_tangent>` **(** **)** |
  111. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. .. rst-class:: classref-section-separator
  113. ----
  114. .. rst-class:: classref-descriptions-group
  115. Constants
  116. ---------
  117. .. _class_Vector2_constant_AXIS_X:
  118. .. rst-class:: classref-constant
  119. **AXIS_X** = ``0``
  120. Enumerated value for the X axis.
  121. .. _class_Vector2_constant_AXIS_Y:
  122. .. rst-class:: classref-constant
  123. **AXIS_Y** = ``1``
  124. Enumerated value for the Y axis.
  125. .. _class_Vector2_constant_ZERO:
  126. .. rst-class:: classref-constant
  127. **ZERO** = ``Vector2( 0, 0 )``
  128. Zero vector, a vector with all components set to ``0``.
  129. .. _class_Vector2_constant_ONE:
  130. .. rst-class:: classref-constant
  131. **ONE** = ``Vector2( 1, 1 )``
  132. One vector, a vector with all components set to ``1``.
  133. .. _class_Vector2_constant_INF:
  134. .. rst-class:: classref-constant
  135. **INF** = ``Vector2( inf, inf )``
  136. Infinity vector, a vector with all components set to :ref:`@GDScript.INF<class_@GDScript_constant_INF>`.
  137. .. _class_Vector2_constant_LEFT:
  138. .. rst-class:: classref-constant
  139. **LEFT** = ``Vector2( -1, 0 )``
  140. Left unit vector. Represents the direction of left.
  141. .. _class_Vector2_constant_RIGHT:
  142. .. rst-class:: classref-constant
  143. **RIGHT** = ``Vector2( 1, 0 )``
  144. Right unit vector. Represents the direction of right.
  145. .. _class_Vector2_constant_UP:
  146. .. rst-class:: classref-constant
  147. **UP** = ``Vector2( 0, -1 )``
  148. Up unit vector. Y is down in 2D, so this vector points -Y.
  149. .. _class_Vector2_constant_DOWN:
  150. .. rst-class:: classref-constant
  151. **DOWN** = ``Vector2( 0, 1 )``
  152. Down unit vector. Y is down in 2D, so this vector points +Y.
  153. .. rst-class:: classref-section-separator
  154. ----
  155. .. rst-class:: classref-descriptions-group
  156. Property Descriptions
  157. ---------------------
  158. .. _class_Vector2_property_x:
  159. .. rst-class:: classref-property
  160. :ref:`float<class_float>` **x** = ``0.0``
  161. The vector's X component. Also accessible by using the index position ``[0]``.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Vector2_property_y:
  165. .. rst-class:: classref-property
  166. :ref:`float<class_float>` **y** = ``0.0``
  167. The vector's Y component. Also accessible by using the index position ``[1]``.
  168. .. rst-class:: classref-section-separator
  169. ----
  170. .. rst-class:: classref-descriptions-group
  171. Method Descriptions
  172. -------------------
  173. .. _class_Vector2_method_Vector2:
  174. .. rst-class:: classref-method
  175. :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  176. Constructs a new Vector2 from the given ``x`` and ``y``.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_Vector2_method_abs:
  180. .. rst-class:: classref-method
  181. :ref:`Vector2<class_Vector2>` **abs** **(** **)**
  182. Returns a new vector with all components in absolute values (i.e. positive).
  183. .. rst-class:: classref-item-separator
  184. ----
  185. .. _class_Vector2_method_angle:
  186. .. rst-class:: classref-method
  187. :ref:`float<class_float>` **angle** **(** **)**
  188. Returns this vector's angle with respect to the positive X axis, or ``(1, 0)`` vector, in radians.
  189. 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).
  190. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png>`__\
  191. 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)``.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_Vector2_method_angle_to:
  195. .. rst-class:: classref-method
  196. :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  197. Returns the angle to the given vector, in radians.
  198. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png>`__
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_Vector2_method_angle_to_point:
  202. .. rst-class:: classref-method
  203. :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)**
  204. Returns the angle between the line connecting the two points and the X axis, in radians.
  205. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/3.6/img/vector2_angle_to_point.png>`__
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_Vector2_method_aspect:
  209. .. rst-class:: classref-method
  210. :ref:`float<class_float>` **aspect** **(** **)**
  211. Returns the aspect ratio of this vector, the ratio of :ref:`x<class_Vector2_property_x>` to :ref:`y<class_Vector2_property_y>`.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_Vector2_method_bounce:
  215. .. rst-class:: classref-method
  216. :ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)**
  217. Returns the vector "bounced off" from a plane defined by the given normal.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_Vector2_method_ceil:
  221. .. rst-class:: classref-method
  222. :ref:`Vector2<class_Vector2>` **ceil** **(** **)**
  223. Returns a new vector with all components rounded up (towards positive infinity).
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Vector2_method_clamped:
  227. .. rst-class:: classref-method
  228. :ref:`Vector2<class_Vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  229. Deprecated, please use :ref:`limit_length<class_Vector2_method_limit_length>` instead.
  230. Returns the vector with a maximum length by limiting its length to ``length``.
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _class_Vector2_method_cross:
  234. .. rst-class:: classref-method
  235. :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)**
  236. Returns the 2D analog of the cross product for this vector and ``with``.
  237. 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.
  238. \ **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.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Vector2_method_cubic_interpolate:
  242. .. rst-class:: classref-method
  243. :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 **)**
  244. 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.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_Vector2_method_direction_to:
  248. .. rst-class:: classref-method
  249. :ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` b **)**
  250. Returns the normalized vector pointing from this vector to ``b``. This is equivalent to using ``(b - a).normalized()``.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_Vector2_method_distance_squared_to:
  254. .. rst-class:: classref-method
  255. :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  256. Returns the squared distance between this vector and ``b``.
  257. 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.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_Vector2_method_distance_to:
  261. .. rst-class:: classref-method
  262. :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  263. Returns the distance between this vector and ``to``.
  264. .. rst-class:: classref-item-separator
  265. ----
  266. .. _class_Vector2_method_dot:
  267. .. rst-class:: classref-method
  268. :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)**
  269. 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.
  270. 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.
  271. 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.
  272. \ **Note:** ``a.dot(b)`` is equivalent to ``b.dot(a)``.
  273. .. rst-class:: classref-item-separator
  274. ----
  275. .. _class_Vector2_method_floor:
  276. .. rst-class:: classref-method
  277. :ref:`Vector2<class_Vector2>` **floor** **(** **)**
  278. Returns a new vector with all components rounded down (towards negative infinity).
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_Vector2_method_is_equal_approx:
  282. .. rst-class:: classref-method
  283. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Vector2<class_Vector2>` v **)**
  284. 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.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_Vector2_method_is_normalized:
  288. .. rst-class:: classref-method
  289. :ref:`bool<class_bool>` **is_normalized** **(** **)**
  290. Returns ``true`` if the vector is normalized, ``false`` otherwise.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_Vector2_method_is_zero_approx:
  294. .. rst-class:: classref-method
  295. :ref:`bool<class_bool>` **is_zero_approx** **(** **)**
  296. 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.
  297. This method is faster than using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` with one value as a zero vector.
  298. .. rst-class:: classref-item-separator
  299. ----
  300. .. _class_Vector2_method_length:
  301. .. rst-class:: classref-method
  302. :ref:`float<class_float>` **length** **(** **)**
  303. Returns the length (magnitude) of this vector.
  304. .. rst-class:: classref-item-separator
  305. ----
  306. .. _class_Vector2_method_length_squared:
  307. .. rst-class:: classref-method
  308. :ref:`float<class_float>` **length_squared** **(** **)**
  309. Returns the squared length (squared magnitude) of this vector.
  310. 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.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_Vector2_method_limit_length:
  314. .. rst-class:: classref-method
  315. :ref:`Vector2<class_Vector2>` **limit_length** **(** :ref:`float<class_float>` length=1.0 **)**
  316. Returns the vector with a maximum length by limiting its length to ``length``.
  317. .. rst-class:: classref-item-separator
  318. ----
  319. .. _class_Vector2_method_linear_interpolate:
  320. .. rst-class:: classref-method
  321. :ref:`Vector2<class_Vector2>` **linear_interpolate** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
  322. 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.
  323. .. rst-class:: classref-item-separator
  324. ----
  325. .. _class_Vector2_method_move_toward:
  326. .. rst-class:: classref-method
  327. :ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)**
  328. Returns a new vector moved toward ``to`` by the fixed ``delta`` amount. Will not go past the final value.
  329. .. rst-class:: classref-item-separator
  330. ----
  331. .. _class_Vector2_method_normalized:
  332. .. rst-class:: classref-method
  333. :ref:`Vector2<class_Vector2>` **normalized** **(** **)**
  334. Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_Vector2_method_posmod:
  338. .. rst-class:: classref-method
  339. :ref:`Vector2<class_Vector2>` **posmod** **(** :ref:`float<class_float>` mod **)**
  340. Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``mod``.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_Vector2_method_posmodv:
  344. .. rst-class:: classref-method
  345. :ref:`Vector2<class_Vector2>` **posmodv** **(** :ref:`Vector2<class_Vector2>` modv **)**
  346. Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``modv``'s components.
  347. .. rst-class:: classref-item-separator
  348. ----
  349. .. _class_Vector2_method_project:
  350. .. rst-class:: classref-method
  351. :ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)**
  352. Returns this vector projected onto the vector ``b``.
  353. .. rst-class:: classref-item-separator
  354. ----
  355. .. _class_Vector2_method_reflect:
  356. .. rst-class:: classref-method
  357. :ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)**
  358. Returns the vector reflected (i.e. mirrored, or symmetric) over a line defined by the given direction vector ``n``.
  359. .. rst-class:: classref-item-separator
  360. ----
  361. .. _class_Vector2_method_rotated:
  362. .. rst-class:: classref-method
  363. :ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` angle **)**
  364. Returns the vector rotated by ``angle`` (in radians). See also :ref:`@GDScript.deg2rad<class_@GDScript_method_deg2rad>`.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_Vector2_method_round:
  368. .. rst-class:: classref-method
  369. :ref:`Vector2<class_Vector2>` **round** **(** **)**
  370. Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_Vector2_method_sign:
  374. .. rst-class:: classref-method
  375. :ref:`Vector2<class_Vector2>` **sign** **(** **)**
  376. 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.
  377. .. rst-class:: classref-item-separator
  378. ----
  379. .. _class_Vector2_method_slerp:
  380. .. rst-class:: classref-method
  381. :ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
  382. 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.
  383. \ **Note:** Both vectors must be normalized.
  384. .. rst-class:: classref-item-separator
  385. ----
  386. .. _class_Vector2_method_slide:
  387. .. rst-class:: classref-method
  388. :ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)**
  389. Returns this vector slid along a plane defined by the given normal.
  390. .. rst-class:: classref-item-separator
  391. ----
  392. .. _class_Vector2_method_snapped:
  393. .. rst-class:: classref-method
  394. :ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` by **)**
  395. 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.
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_Vector2_method_tangent:
  399. .. rst-class:: classref-method
  400. :ref:`Vector2<class_Vector2>` **tangent** **(** **)**
  401. Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
  402. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  403. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  404. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  405. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`