class_vector2.rst 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/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:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |
  77. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |
  79. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>` **(** :ref:`float<class_float>` length=1.0 **)** |
  81. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector2<class_Vector2>` | :ref:`linear_interpolate<class_Vector2_method_linear_interpolate>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
  83. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |
  85. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |
  87. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>` **(** :ref:`float<class_float>` mod **)** |
  89. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>` **(** :ref:`Vector2<class_Vector2>` modv **)** |
  91. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |
  93. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  95. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` angle **)** |
  97. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |
  99. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>` **(** **)** |
  101. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |
  103. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  105. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` by **)** |
  107. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`Vector2<class_Vector2>` | :ref:`tangent<class_Vector2_method_tangent>` **(** **)** |
  109. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. .. rst-class:: classref-section-separator
  111. ----
  112. .. rst-class:: classref-descriptions-group
  113. Constants
  114. ---------
  115. .. _class_Vector2_constant_AXIS_X:
  116. .. rst-class:: classref-constant
  117. **AXIS_X** = ``0``
  118. Enumerated value for the X axis.
  119. .. _class_Vector2_constant_AXIS_Y:
  120. .. rst-class:: classref-constant
  121. **AXIS_Y** = ``1``
  122. Enumerated value for the Y axis.
  123. .. _class_Vector2_constant_ZERO:
  124. .. rst-class:: classref-constant
  125. **ZERO** = ``Vector2( 0, 0 )``
  126. Zero vector, a vector with all components set to ``0``.
  127. .. _class_Vector2_constant_ONE:
  128. .. rst-class:: classref-constant
  129. **ONE** = ``Vector2( 1, 1 )``
  130. One vector, a vector with all components set to ``1``.
  131. .. _class_Vector2_constant_INF:
  132. .. rst-class:: classref-constant
  133. **INF** = ``Vector2( inf, inf )``
  134. Infinity vector, a vector with all components set to :ref:`@GDScript.INF<class_@GDScript_constant_INF>`.
  135. .. _class_Vector2_constant_LEFT:
  136. .. rst-class:: classref-constant
  137. **LEFT** = ``Vector2( -1, 0 )``
  138. Left unit vector. Represents the direction of left.
  139. .. _class_Vector2_constant_RIGHT:
  140. .. rst-class:: classref-constant
  141. **RIGHT** = ``Vector2( 1, 0 )``
  142. Right unit vector. Represents the direction of right.
  143. .. _class_Vector2_constant_UP:
  144. .. rst-class:: classref-constant
  145. **UP** = ``Vector2( 0, -1 )``
  146. Up unit vector. Y is down in 2D, so this vector points -Y.
  147. .. _class_Vector2_constant_DOWN:
  148. .. rst-class:: classref-constant
  149. **DOWN** = ``Vector2( 0, 1 )``
  150. Down unit vector. Y is down in 2D, so this vector points +Y.
  151. .. rst-class:: classref-section-separator
  152. ----
  153. .. rst-class:: classref-descriptions-group
  154. Property Descriptions
  155. ---------------------
  156. .. _class_Vector2_property_x:
  157. .. rst-class:: classref-property
  158. :ref:`float<class_float>` **x** = ``0.0``
  159. The vector's X component. Also accessible by using the index position ``[0]``.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_Vector2_property_y:
  163. .. rst-class:: classref-property
  164. :ref:`float<class_float>` **y** = ``0.0``
  165. The vector's Y component. Also accessible by using the index position ``[1]``.
  166. .. rst-class:: classref-section-separator
  167. ----
  168. .. rst-class:: classref-descriptions-group
  169. Method Descriptions
  170. -------------------
  171. .. _class_Vector2_method_Vector2:
  172. .. rst-class:: classref-method
  173. :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  174. Constructs a new Vector2 from the given ``x`` and ``y``.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_Vector2_method_abs:
  178. .. rst-class:: classref-method
  179. :ref:`Vector2<class_Vector2>` **abs** **(** **)**
  180. Returns a new vector with all components in absolute values (i.e. positive).
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_Vector2_method_angle:
  184. .. rst-class:: classref-method
  185. :ref:`float<class_float>` **angle** **(** **)**
  186. Returns this vector's angle with respect to the positive X axis, or ``(1, 0)`` vector, in radians.
  187. 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).
  188. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png>`__\
  189. 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)``.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_Vector2_method_angle_to:
  193. .. rst-class:: classref-method
  194. :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  195. Returns the angle to the given vector, in radians.
  196. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png>`__
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_Vector2_method_angle_to_point:
  200. .. rst-class:: classref-method
  201. :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)**
  202. Returns the angle between the line connecting the two points and the X axis, in radians.
  203. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/stable/img/vector2_angle_to_point.png>`__
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_Vector2_method_aspect:
  207. .. rst-class:: classref-method
  208. :ref:`float<class_float>` **aspect** **(** **)**
  209. Returns the aspect ratio of this vector, the ratio of :ref:`x<class_Vector2_property_x>` to :ref:`y<class_Vector2_property_y>`.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_Vector2_method_bounce:
  213. .. rst-class:: classref-method
  214. :ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)**
  215. Returns the vector "bounced off" from a plane defined by the given normal.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_Vector2_method_ceil:
  219. .. rst-class:: classref-method
  220. :ref:`Vector2<class_Vector2>` **ceil** **(** **)**
  221. Returns a new vector with all components rounded up (towards positive infinity).
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_Vector2_method_clamped:
  225. .. rst-class:: classref-method
  226. :ref:`Vector2<class_Vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  227. Deprecated, please use :ref:`limit_length<class_Vector2_method_limit_length>` instead.
  228. Returns the vector with a maximum length by limiting its length to ``length``.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_Vector2_method_cross:
  232. .. rst-class:: classref-method
  233. :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)**
  234. Returns the 2D analog of the cross product for this vector and ``with``.
  235. 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.
  236. \ **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.
  237. .. rst-class:: classref-item-separator
  238. ----
  239. .. _class_Vector2_method_cubic_interpolate:
  240. .. rst-class:: classref-method
  241. :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 **)**
  242. 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.
  243. .. rst-class:: classref-item-separator
  244. ----
  245. .. _class_Vector2_method_direction_to:
  246. .. rst-class:: classref-method
  247. :ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` b **)**
  248. Returns the normalized vector pointing from this vector to ``b``. This is equivalent to using ``(b - a).normalized()``.
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_Vector2_method_distance_squared_to:
  252. .. rst-class:: classref-method
  253. :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  254. Returns the squared distance between this vector and ``b``.
  255. 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.
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_Vector2_method_distance_to:
  259. .. rst-class:: classref-method
  260. :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  261. Returns the distance between this vector and ``to``.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_Vector2_method_dot:
  265. .. rst-class:: classref-method
  266. :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)**
  267. 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.
  268. 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.
  269. 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.
  270. \ **Note:** ``a.dot(b)`` is equivalent to ``b.dot(a)``.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_Vector2_method_floor:
  274. .. rst-class:: classref-method
  275. :ref:`Vector2<class_Vector2>` **floor** **(** **)**
  276. Returns a new vector with all components rounded down (towards negative infinity).
  277. .. rst-class:: classref-item-separator
  278. ----
  279. .. _class_Vector2_method_is_equal_approx:
  280. .. rst-class:: classref-method
  281. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Vector2<class_Vector2>` v **)**
  282. 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.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_Vector2_method_is_normalized:
  286. .. rst-class:: classref-method
  287. :ref:`bool<class_bool>` **is_normalized** **(** **)**
  288. Returns ``true`` if the vector is normalized, ``false`` otherwise.
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_Vector2_method_length:
  292. .. rst-class:: classref-method
  293. :ref:`float<class_float>` **length** **(** **)**
  294. Returns the length (magnitude) of this vector.
  295. .. rst-class:: classref-item-separator
  296. ----
  297. .. _class_Vector2_method_length_squared:
  298. .. rst-class:: classref-method
  299. :ref:`float<class_float>` **length_squared** **(** **)**
  300. Returns the squared length (squared magnitude) of this vector.
  301. 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.
  302. .. rst-class:: classref-item-separator
  303. ----
  304. .. _class_Vector2_method_limit_length:
  305. .. rst-class:: classref-method
  306. :ref:`Vector2<class_Vector2>` **limit_length** **(** :ref:`float<class_float>` length=1.0 **)**
  307. Returns the vector with a maximum length by limiting its length to ``length``.
  308. .. rst-class:: classref-item-separator
  309. ----
  310. .. _class_Vector2_method_linear_interpolate:
  311. .. rst-class:: classref-method
  312. :ref:`Vector2<class_Vector2>` **linear_interpolate** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
  313. 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.
  314. .. rst-class:: classref-item-separator
  315. ----
  316. .. _class_Vector2_method_move_toward:
  317. .. rst-class:: classref-method
  318. :ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)**
  319. Returns a new vector moved toward ``to`` by the fixed ``delta`` amount. Will not go past the final value.
  320. .. rst-class:: classref-item-separator
  321. ----
  322. .. _class_Vector2_method_normalized:
  323. .. rst-class:: classref-method
  324. :ref:`Vector2<class_Vector2>` **normalized** **(** **)**
  325. Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
  326. .. rst-class:: classref-item-separator
  327. ----
  328. .. _class_Vector2_method_posmod:
  329. .. rst-class:: classref-method
  330. :ref:`Vector2<class_Vector2>` **posmod** **(** :ref:`float<class_float>` mod **)**
  331. Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``mod``.
  332. .. rst-class:: classref-item-separator
  333. ----
  334. .. _class_Vector2_method_posmodv:
  335. .. rst-class:: classref-method
  336. :ref:`Vector2<class_Vector2>` **posmodv** **(** :ref:`Vector2<class_Vector2>` modv **)**
  337. Returns a vector composed of the :ref:`@GDScript.fposmod<class_@GDScript_method_fposmod>` of this vector's components and ``modv``'s components.
  338. .. rst-class:: classref-item-separator
  339. ----
  340. .. _class_Vector2_method_project:
  341. .. rst-class:: classref-method
  342. :ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)**
  343. Returns this vector projected onto the vector ``b``.
  344. .. rst-class:: classref-item-separator
  345. ----
  346. .. _class_Vector2_method_reflect:
  347. .. rst-class:: classref-method
  348. :ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)**
  349. Returns the vector reflected (i.e. mirrored, or symmetric) over a line defined by the given direction vector ``n``.
  350. .. rst-class:: classref-item-separator
  351. ----
  352. .. _class_Vector2_method_rotated:
  353. .. rst-class:: classref-method
  354. :ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` angle **)**
  355. Returns the vector rotated by ``angle`` (in radians). See also :ref:`@GDScript.deg2rad<class_@GDScript_method_deg2rad>`.
  356. .. rst-class:: classref-item-separator
  357. ----
  358. .. _class_Vector2_method_round:
  359. .. rst-class:: classref-method
  360. :ref:`Vector2<class_Vector2>` **round** **(** **)**
  361. Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _class_Vector2_method_sign:
  365. .. rst-class:: classref-method
  366. :ref:`Vector2<class_Vector2>` **sign** **(** **)**
  367. 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.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_Vector2_method_slerp:
  371. .. rst-class:: classref-method
  372. :ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)**
  373. 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.
  374. \ **Note:** Both vectors must be normalized.
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_Vector2_method_slide:
  378. .. rst-class:: classref-method
  379. :ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)**
  380. Returns this vector slid along a plane defined by the given normal.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_Vector2_method_snapped:
  384. .. rst-class:: classref-method
  385. :ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` by **)**
  386. 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.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_Vector2_method_tangent:
  390. .. rst-class:: classref-method
  391. :ref:`Vector2<class_Vector2>` **tangent** **(** **)**
  392. Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
  393. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  394. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  395. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  396. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`