class_vector2.rst 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Vector2.xml.
  6. .. _class_Vector2:
  7. Vector2
  8. =======
  9. A 2D vector using floating point coordinates.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. A 2-element structure that can be used to represent 2D coordinates or any other pair of numeric values.
  14. It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike :ref:`float<class_float>` which is always 64-bit. If double precision is needed, compile the engine with the option ``precision=double``.
  15. See :ref:`Vector2i<class_Vector2i>` for its integer counterpart.
  16. \ **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``.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Math documentation index <../tutorials/math/index>`
  21. - :doc:`Vector math <../tutorials/math/vector_math>`
  22. - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
  23. - `3Blue1Brown Essence of Linear Algebra <https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab>`__
  24. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  25. - `All 2D Demos <https://github.com/godotengine/godot-demo-projects/tree/master/2d>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +---------------------------+------------------------------------+---------+
  32. | :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` | ``0.0`` |
  33. +---------------------------+------------------------------------+---------+
  34. | :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` | ``0.0`` |
  35. +---------------------------+------------------------------------+---------+
  36. .. rst-class:: classref-reftable-group
  37. Constructors
  38. ------------
  39. .. table::
  40. :widths: auto
  41. +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** **)** |
  43. +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`Vector2<class_Vector2>` from **)** |
  45. +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`Vector2i<class_Vector2i>` from **)** |
  47. +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  49. +-------------------------------+------------------------------------------------------------------------------------------------------------------------+
  50. .. rst-class:: classref-reftable-group
  51. Methods
  52. -------
  53. .. table::
  54. :widths: auto
  55. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>` **(** **)** |const| |
  57. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>` **(** **)** |const| |
  59. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  61. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  63. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>` **(** **)** |const| |
  65. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Vector2<class_Vector2>` | :ref:`bezier_derivative<class_Vector2_method_bezier_derivative>` **(** :ref:`Vector2<class_Vector2>` control_1, :ref:`Vector2<class_Vector2>` control_2, :ref:`Vector2<class_Vector2>` end, :ref:`float<class_float>` t **)** |const| |
  67. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Vector2<class_Vector2>` | :ref:`bezier_interpolate<class_Vector2_method_bezier_interpolate>` **(** :ref:`Vector2<class_Vector2>` control_1, :ref:`Vector2<class_Vector2>` control_2, :ref:`Vector2<class_Vector2>` end, :ref:`float<class_float>` t **)** |const| |
  69. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
  71. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>` **(** **)** |const| |
  73. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Vector2<class_Vector2>` | :ref:`clamp<class_Vector2_method_clamp>` **(** :ref:`Vector2<class_Vector2>` min, :ref:`Vector2<class_Vector2>` max **)** |const| |
  75. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>` **(** :ref:`Vector2<class_Vector2>` with **)** |const| |
  77. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :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| |
  79. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector2<class_Vector2>` | :ref:`cubic_interpolate_in_time<class_Vector2_method_cubic_interpolate_in_time>` **(** :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` pre_a, :ref:`Vector2<class_Vector2>` post_b, :ref:`float<class_float>` weight, :ref:`float<class_float>` b_t, :ref:`float<class_float>` pre_a_t, :ref:`float<class_float>` post_b_t **)** |const| |
  81. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  83. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  85. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  87. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>` **(** :ref:`Vector2<class_Vector2>` with **)** |const| |
  89. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>` **(** **)** |const| |
  91. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Vector2<class_Vector2>` | :ref:`from_angle<class_Vector2_method_from_angle>` **(** :ref:`float<class_float>` angle **)** |static| |
  93. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` **(** :ref:`Vector2<class_Vector2>` to **)** |const| |
  95. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Vector2_method_is_finite>` **(** **)** |const| |
  97. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>` **(** **)** |const| |
  99. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`is_zero_approx<class_Vector2_method_is_zero_approx>` **(** **)** |const| |
  101. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |const| |
  103. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |const| |
  105. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`Vector2<class_Vector2>` | :ref:`lerp<class_Vector2_method_lerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const| |
  107. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>` **(** :ref:`float<class_float>` length=1.0 **)** |const| |
  109. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`int<class_int>` | :ref:`max_axis_index<class_Vector2_method_max_axis_index>` **(** **)** |const| |
  111. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`int<class_int>` | :ref:`min_axis_index<class_Vector2_method_min_axis_index>` **(** **)** |const| |
  113. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |const| |
  115. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |const| |
  117. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Vector2<class_Vector2>` | :ref:`orthogonal<class_Vector2_method_orthogonal>` **(** **)** |const| |
  119. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>` **(** :ref:`float<class_float>` mod **)** |const| |
  121. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>` **(** :ref:`Vector2<class_Vector2>` modv **)** |const| |
  123. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |const| |
  125. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
  127. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` angle **)** |const| |
  129. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |const| |
  131. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>` **(** **)** |const| |
  133. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const| |
  135. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |const| |
  137. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` step **)** |const| |
  139. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. .. rst-class:: classref-reftable-group
  141. Operators
  142. ---------
  143. .. table::
  144. :widths: auto
  145. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Vector2_operator_neq_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  147. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Transform2D>` **(** :ref:`Transform2D<class_Transform2D>` right **)** |
  149. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  151. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
  153. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
  155. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`Vector2<class_Vector2>` | :ref:`operator +<class_Vector2_operator_sum_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  157. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`Vector2<class_Vector2>` | :ref:`operator -<class_Vector2_operator_dif_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  159. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  161. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
  163. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
  165. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`bool<class_bool>` | :ref:`operator \<<class_Vector2_operator_lt_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  167. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`bool<class_bool>` | :ref:`operator \<=<class_Vector2_operator_lte_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  169. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Vector2_operator_eq_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  171. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`bool<class_bool>` | :ref:`operator ><class_Vector2_operator_gt_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  173. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`bool<class_bool>` | :ref:`operator >=<class_Vector2_operator_gte_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  175. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`float<class_float>` | :ref:`operator []<class_Vector2_operator_idx_int>` **(** :ref:`int<class_int>` index **)** |
  177. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  178. | :ref:`Vector2<class_Vector2>` | :ref:`operator unary+<class_Vector2_operator_unplus>` **(** **)** |
  179. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  180. | :ref:`Vector2<class_Vector2>` | :ref:`operator unary-<class_Vector2_operator_unminus>` **(** **)** |
  181. +-------------------------------+-------------------------------------------------------------------------------------------------------------------+
  182. .. rst-class:: classref-section-separator
  183. ----
  184. .. rst-class:: classref-descriptions-group
  185. Constants
  186. ---------
  187. .. _class_Vector2_constant_AXIS_X:
  188. .. rst-class:: classref-constant
  189. **AXIS_X** = ``0``
  190. Enumerated value for the X axis. Returned by :ref:`max_axis_index<class_Vector2_method_max_axis_index>` and :ref:`min_axis_index<class_Vector2_method_min_axis_index>`.
  191. .. _class_Vector2_constant_AXIS_Y:
  192. .. rst-class:: classref-constant
  193. **AXIS_Y** = ``1``
  194. Enumerated value for the Y axis. Returned by :ref:`max_axis_index<class_Vector2_method_max_axis_index>` and :ref:`min_axis_index<class_Vector2_method_min_axis_index>`.
  195. .. _class_Vector2_constant_ZERO:
  196. .. rst-class:: classref-constant
  197. **ZERO** = ``Vector2(0, 0)``
  198. Zero vector, a vector with all components set to ``0``.
  199. .. _class_Vector2_constant_ONE:
  200. .. rst-class:: classref-constant
  201. **ONE** = ``Vector2(1, 1)``
  202. One vector, a vector with all components set to ``1``.
  203. .. _class_Vector2_constant_INF:
  204. .. rst-class:: classref-constant
  205. **INF** = ``Vector2(inf, inf)``
  206. Infinity vector, a vector with all components set to :ref:`@GDScript.INF<class_@GDScript_constant_INF>`.
  207. .. _class_Vector2_constant_LEFT:
  208. .. rst-class:: classref-constant
  209. **LEFT** = ``Vector2(-1, 0)``
  210. Left unit vector. Represents the direction of left.
  211. .. _class_Vector2_constant_RIGHT:
  212. .. rst-class:: classref-constant
  213. **RIGHT** = ``Vector2(1, 0)``
  214. Right unit vector. Represents the direction of right.
  215. .. _class_Vector2_constant_UP:
  216. .. rst-class:: classref-constant
  217. **UP** = ``Vector2(0, -1)``
  218. Up unit vector. Y is down in 2D, so this vector points -Y.
  219. .. _class_Vector2_constant_DOWN:
  220. .. rst-class:: classref-constant
  221. **DOWN** = ``Vector2(0, 1)``
  222. Down unit vector. Y is down in 2D, so this vector points +Y.
  223. .. rst-class:: classref-section-separator
  224. ----
  225. .. rst-class:: classref-descriptions-group
  226. Property Descriptions
  227. ---------------------
  228. .. _class_Vector2_property_x:
  229. .. rst-class:: classref-property
  230. :ref:`float<class_float>` **x** = ``0.0``
  231. The vector's X component. Also accessible by using the index position ``[0]``.
  232. .. rst-class:: classref-item-separator
  233. ----
  234. .. _class_Vector2_property_y:
  235. .. rst-class:: classref-property
  236. :ref:`float<class_float>` **y** = ``0.0``
  237. The vector's Y component. Also accessible by using the index position ``[1]``.
  238. .. rst-class:: classref-section-separator
  239. ----
  240. .. rst-class:: classref-descriptions-group
  241. Constructor Descriptions
  242. ------------------------
  243. .. _class_Vector2_constructor_Vector2:
  244. .. rst-class:: classref-constructor
  245. :ref:`Vector2<class_Vector2>` **Vector2** **(** **)**
  246. Constructs a default-initialized **Vector2** with all components set to ``0``.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. rst-class:: classref-constructor
  250. :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`Vector2<class_Vector2>` from **)**
  251. Constructs a **Vector2** as a copy of the given **Vector2**.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. rst-class:: classref-constructor
  255. :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`Vector2i<class_Vector2i>` from **)**
  256. Constructs a new **Vector2** from :ref:`Vector2i<class_Vector2i>`.
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. rst-class:: classref-constructor
  260. :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  261. Constructs a new **Vector2** from the given ``x`` and ``y``.
  262. .. rst-class:: classref-section-separator
  263. ----
  264. .. rst-class:: classref-descriptions-group
  265. Method Descriptions
  266. -------------------
  267. .. _class_Vector2_method_abs:
  268. .. rst-class:: classref-method
  269. :ref:`Vector2<class_Vector2>` **abs** **(** **)** |const|
  270. Returns a new vector with all components in absolute values (i.e. positive).
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_Vector2_method_angle:
  274. .. rst-class:: classref-method
  275. :ref:`float<class_float>` **angle** **(** **)** |const|
  276. Returns this vector's angle with respect to the positive X axis, or ``(1, 0)`` vector, in radians.
  277. 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).
  278. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png>`__\
  279. 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)``.
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_Vector2_method_angle_to:
  283. .. rst-class:: classref-method
  284. :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  285. Returns the angle to the given vector, in radians.
  286. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png>`__
  287. .. rst-class:: classref-item-separator
  288. ----
  289. .. _class_Vector2_method_angle_to_point:
  290. .. rst-class:: classref-method
  291. :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  292. Returns the angle between the line connecting the two points and the X axis, in radians.
  293. \ ``a.angle_to_point(b)`` is equivalent of doing ``(b - a).angle()``.
  294. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to_point.png>`__
  295. .. rst-class:: classref-item-separator
  296. ----
  297. .. _class_Vector2_method_aspect:
  298. .. rst-class:: classref-method
  299. :ref:`float<class_float>` **aspect** **(** **)** |const|
  300. Returns the aspect ratio of this vector, the ratio of :ref:`x<class_Vector2_property_x>` to :ref:`y<class_Vector2_property_y>`.
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_Vector2_method_bezier_derivative:
  304. .. rst-class:: classref-method
  305. :ref:`Vector2<class_Vector2>` **bezier_derivative** **(** :ref:`Vector2<class_Vector2>` control_1, :ref:`Vector2<class_Vector2>` control_2, :ref:`Vector2<class_Vector2>` end, :ref:`float<class_float>` t **)** |const|
  306. Returns the derivative at the given ``t`` on the `Bézier curve <https://en.wikipedia.org/wiki/B%C3%A9zier_curve>`__ defined by this vector and the given ``control_1``, ``control_2``, and ``end`` points.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_Vector2_method_bezier_interpolate:
  310. .. rst-class:: classref-method
  311. :ref:`Vector2<class_Vector2>` **bezier_interpolate** **(** :ref:`Vector2<class_Vector2>` control_1, :ref:`Vector2<class_Vector2>` control_2, :ref:`Vector2<class_Vector2>` end, :ref:`float<class_float>` t **)** |const|
  312. Returns the point at the given ``t`` on the `Bézier curve <https://en.wikipedia.org/wiki/B%C3%A9zier_curve>`__ defined by this vector and the given ``control_1``, ``control_2``, and ``end`` points.
  313. .. rst-class:: classref-item-separator
  314. ----
  315. .. _class_Vector2_method_bounce:
  316. .. rst-class:: classref-method
  317. :ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
  318. Returns a new vector "bounced off" from a plane defined by the given normal.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_Vector2_method_ceil:
  322. .. rst-class:: classref-method
  323. :ref:`Vector2<class_Vector2>` **ceil** **(** **)** |const|
  324. Returns a new vector with all components rounded up (towards positive infinity).
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_Vector2_method_clamp:
  328. .. rst-class:: classref-method
  329. :ref:`Vector2<class_Vector2>` **clamp** **(** :ref:`Vector2<class_Vector2>` min, :ref:`Vector2<class_Vector2>` max **)** |const|
  330. 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.
  331. .. rst-class:: classref-item-separator
  332. ----
  333. .. _class_Vector2_method_cross:
  334. .. rst-class:: classref-method
  335. :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)** |const|
  336. Returns the 2D analog of the cross product for this vector and ``with``.
  337. 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.
  338. \ **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.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_Vector2_method_cubic_interpolate:
  342. .. rst-class:: classref-method
  343. :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|
  344. Performs a cubic interpolation 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.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_Vector2_method_cubic_interpolate_in_time:
  348. .. rst-class:: classref-method
  349. :ref:`Vector2<class_Vector2>` **cubic_interpolate_in_time** **(** :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` pre_a, :ref:`Vector2<class_Vector2>` post_b, :ref:`float<class_float>` weight, :ref:`float<class_float>` b_t, :ref:`float<class_float>` pre_a_t, :ref:`float<class_float>` post_b_t **)** |const|
  350. Performs a cubic interpolation 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.
  351. It can perform smoother interpolation than :ref:`cubic_interpolate<class_Vector2_method_cubic_interpolate>` by the time values.
  352. .. rst-class:: classref-item-separator
  353. ----
  354. .. _class_Vector2_method_direction_to:
  355. .. rst-class:: classref-method
  356. :ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  357. Returns the normalized vector pointing from this vector to ``to``. This is equivalent to using ``(b - a).normalized()``.
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_Vector2_method_distance_squared_to:
  361. .. rst-class:: classref-method
  362. :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  363. Returns the squared distance between this vector and ``to``.
  364. 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.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_Vector2_method_distance_to:
  368. .. rst-class:: classref-method
  369. :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  370. Returns the distance between this vector and ``to``.
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_Vector2_method_dot:
  374. .. rst-class:: classref-method
  375. :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)** |const|
  376. 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.
  377. 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.
  378. 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.
  379. \ **Note:** ``a.dot(b)`` is equivalent to ``b.dot(a)``.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_Vector2_method_floor:
  383. .. rst-class:: classref-method
  384. :ref:`Vector2<class_Vector2>` **floor** **(** **)** |const|
  385. Returns a new vector with all components rounded down (towards negative infinity).
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_Vector2_method_from_angle:
  389. .. rst-class:: classref-method
  390. :ref:`Vector2<class_Vector2>` **from_angle** **(** :ref:`float<class_float>` angle **)** |static|
  391. 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)``.
  392. ::
  393. print(Vector2.from_angle(0)) # Prints (1, 0).
  394. print(Vector2(1, 0).angle()) # Prints 0, which is the angle used above.
  395. print(Vector2.from_angle(PI / 2)) # Prints (0, 1).
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_Vector2_method_is_equal_approx:
  399. .. rst-class:: classref-method
  400. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Vector2<class_Vector2>` to **)** |const|
  401. Returns ``true`` if this vector and ``to`` are approximately equal, by running :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on each component.
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_Vector2_method_is_finite:
  405. .. rst-class:: classref-method
  406. :ref:`bool<class_bool>` **is_finite** **(** **)** |const|
  407. Returns ``true`` if this vector is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on each component.
  408. .. rst-class:: classref-item-separator
  409. ----
  410. .. _class_Vector2_method_is_normalized:
  411. .. rst-class:: classref-method
  412. :ref:`bool<class_bool>` **is_normalized** **(** **)** |const|
  413. Returns ``true`` if the vector is normalized, i.e. its length is approximately equal to 1.
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_Vector2_method_is_zero_approx:
  417. .. rst-class:: classref-method
  418. :ref:`bool<class_bool>` **is_zero_approx** **(** **)** |const|
  419. Returns ``true`` if this vector's values are approximately zero, by running :ref:`@GlobalScope.is_zero_approx<class_@GlobalScope_method_is_zero_approx>` on each component.
  420. This method is faster than using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` with one value as a zero vector.
  421. .. rst-class:: classref-item-separator
  422. ----
  423. .. _class_Vector2_method_length:
  424. .. rst-class:: classref-method
  425. :ref:`float<class_float>` **length** **(** **)** |const|
  426. Returns the length (magnitude) of this vector.
  427. .. rst-class:: classref-item-separator
  428. ----
  429. .. _class_Vector2_method_length_squared:
  430. .. rst-class:: classref-method
  431. :ref:`float<class_float>` **length_squared** **(** **)** |const|
  432. Returns the squared length (squared magnitude) of this vector.
  433. 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.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_Vector2_method_lerp:
  437. .. rst-class:: classref-method
  438. :ref:`Vector2<class_Vector2>` **lerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const|
  439. 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.
  440. .. rst-class:: classref-item-separator
  441. ----
  442. .. _class_Vector2_method_limit_length:
  443. .. rst-class:: classref-method
  444. :ref:`Vector2<class_Vector2>` **limit_length** **(** :ref:`float<class_float>` length=1.0 **)** |const|
  445. Returns the vector with a maximum length by limiting its length to ``length``.
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _class_Vector2_method_max_axis_index:
  449. .. rst-class:: classref-method
  450. :ref:`int<class_int>` **max_axis_index** **(** **)** |const|
  451. Returns the axis of the vector's highest value. See ``AXIS_*`` constants. If all components are equal, this method returns :ref:`AXIS_X<class_Vector2_constant_AXIS_X>`.
  452. .. rst-class:: classref-item-separator
  453. ----
  454. .. _class_Vector2_method_min_axis_index:
  455. .. rst-class:: classref-method
  456. :ref:`int<class_int>` **min_axis_index** **(** **)** |const|
  457. Returns the axis of the vector's lowest value. See ``AXIS_*`` constants. If all components are equal, this method returns :ref:`AXIS_Y<class_Vector2_constant_AXIS_Y>`.
  458. .. rst-class:: classref-item-separator
  459. ----
  460. .. _class_Vector2_method_move_toward:
  461. .. rst-class:: classref-method
  462. :ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |const|
  463. Returns a new vector moved toward ``to`` by the fixed ``delta`` amount. Will not go past the final value.
  464. .. rst-class:: classref-item-separator
  465. ----
  466. .. _class_Vector2_method_normalized:
  467. .. rst-class:: classref-method
  468. :ref:`Vector2<class_Vector2>` **normalized** **(** **)** |const|
  469. Returns the result of scaling the vector to unit length. Equivalent to ``v / v.length()``. See also :ref:`is_normalized<class_Vector2_method_is_normalized>`.
  470. \ **Note:** This function may return incorrect values if the input vector length is near zero.
  471. .. rst-class:: classref-item-separator
  472. ----
  473. .. _class_Vector2_method_orthogonal:
  474. .. rst-class:: classref-method
  475. :ref:`Vector2<class_Vector2>` **orthogonal** **(** **)** |const|
  476. Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
  477. .. rst-class:: classref-item-separator
  478. ----
  479. .. _class_Vector2_method_posmod:
  480. .. rst-class:: classref-method
  481. :ref:`Vector2<class_Vector2>` **posmod** **(** :ref:`float<class_float>` mod **)** |const|
  482. Returns a vector composed of the :ref:`@GlobalScope.fposmod<class_@GlobalScope_method_fposmod>` of this vector's components and ``mod``.
  483. .. rst-class:: classref-item-separator
  484. ----
  485. .. _class_Vector2_method_posmodv:
  486. .. rst-class:: classref-method
  487. :ref:`Vector2<class_Vector2>` **posmodv** **(** :ref:`Vector2<class_Vector2>` modv **)** |const|
  488. Returns a vector composed of the :ref:`@GlobalScope.fposmod<class_@GlobalScope_method_fposmod>` of this vector's components and ``modv``'s components.
  489. .. rst-class:: classref-item-separator
  490. ----
  491. .. _class_Vector2_method_project:
  492. .. rst-class:: classref-method
  493. :ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)** |const|
  494. Returns the result of projecting the vector onto the given vector ``b``.
  495. .. rst-class:: classref-item-separator
  496. ----
  497. .. _class_Vector2_method_reflect:
  498. .. rst-class:: classref-method
  499. :ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
  500. Returns the result of reflecting the vector from a line defined by the given direction vector ``n``.
  501. .. rst-class:: classref-item-separator
  502. ----
  503. .. _class_Vector2_method_rotated:
  504. .. rst-class:: classref-method
  505. :ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` angle **)** |const|
  506. Returns the result of rotating this vector by ``angle`` (in radians). See also :ref:`@GlobalScope.deg_to_rad<class_@GlobalScope_method_deg_to_rad>`.
  507. .. rst-class:: classref-item-separator
  508. ----
  509. .. _class_Vector2_method_round:
  510. .. rst-class:: classref-method
  511. :ref:`Vector2<class_Vector2>` **round** **(** **)** |const|
  512. Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
  513. .. rst-class:: classref-item-separator
  514. ----
  515. .. _class_Vector2_method_sign:
  516. .. rst-class:: classref-method
  517. :ref:`Vector2<class_Vector2>` **sign** **(** **)** |const|
  518. Returns a new vector with each component set to ``1.0`` if it's positive, ``-1.0`` if it's negative, and ``0.0`` if it's zero. The result is identical to calling :ref:`@GlobalScope.sign<class_@GlobalScope_method_sign>` on each component.
  519. .. rst-class:: classref-item-separator
  520. ----
  521. .. _class_Vector2_method_slerp:
  522. .. rst-class:: classref-method
  523. :ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` weight **)** |const|
  524. 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.
  525. This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like :ref:`lerp<class_Vector2_method_lerp>`.
  526. .. rst-class:: classref-item-separator
  527. ----
  528. .. _class_Vector2_method_slide:
  529. .. rst-class:: classref-method
  530. :ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)** |const|
  531. Returns the result of sliding the vector along a plane defined by the given normal.
  532. .. rst-class:: classref-item-separator
  533. ----
  534. .. _class_Vector2_method_snapped:
  535. .. rst-class:: classref-method
  536. :ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` step **)** |const|
  537. Returns a new vector with each component snapped to the nearest multiple of the corresponding component in ``step``. This can also be used to round the components to an arbitrary number of decimals.
  538. .. rst-class:: classref-section-separator
  539. ----
  540. .. rst-class:: classref-descriptions-group
  541. Operator Descriptions
  542. ---------------------
  543. .. _class_Vector2_operator_neq_Vector2:
  544. .. rst-class:: classref-operator
  545. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Vector2<class_Vector2>` right **)**
  546. Returns ``true`` if the vectors are not equal.
  547. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` instead, which is more reliable.
  548. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  549. .. rst-class:: classref-item-separator
  550. ----
  551. .. _class_Vector2_operator_mul_Transform2D:
  552. .. rst-class:: classref-operator
  553. :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Transform2D<class_Transform2D>` right **)**
  554. Inversely transforms (multiplies) the **Vector2** by the given :ref:`Transform2D<class_Transform2D>` transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
  555. \ ``vector * transform`` is equivalent to ``transform.inverse() * vector``. See :ref:`Transform2D.inverse<class_Transform2D_method_inverse>`.
  556. For transforming by inverse of an affine transformation (e.g. with scaling) ``transform.affine_inverse() * vector`` can be used instead. See :ref:`Transform2D.affine_inverse<class_Transform2D_method_affine_inverse>`.
  557. .. rst-class:: classref-item-separator
  558. ----
  559. .. _class_Vector2_operator_mul_Vector2:
  560. .. rst-class:: classref-operator
  561. :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Vector2<class_Vector2>` right **)**
  562. Multiplies each component of the **Vector2** by the components of the given **Vector2**.
  563. ::
  564. print(Vector2(10, 20) * Vector2(3, 4)) # Prints "(30, 80)"
  565. .. rst-class:: classref-item-separator
  566. ----
  567. .. _class_Vector2_operator_mul_float:
  568. .. rst-class:: classref-operator
  569. :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`float<class_float>` right **)**
  570. Multiplies each component of the **Vector2** by the given :ref:`float<class_float>`.
  571. .. rst-class:: classref-item-separator
  572. ----
  573. .. _class_Vector2_operator_mul_int:
  574. .. rst-class:: classref-operator
  575. :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`int<class_int>` right **)**
  576. Multiplies each component of the **Vector2** by the given :ref:`int<class_int>`.
  577. .. rst-class:: classref-item-separator
  578. ----
  579. .. _class_Vector2_operator_sum_Vector2:
  580. .. rst-class:: classref-operator
  581. :ref:`Vector2<class_Vector2>` **operator +** **(** :ref:`Vector2<class_Vector2>` right **)**
  582. Adds each component of the **Vector2** by the components of the given **Vector2**.
  583. ::
  584. print(Vector2(10, 20) + Vector2(3, 4)) # Prints "(13, 24)"
  585. .. rst-class:: classref-item-separator
  586. ----
  587. .. _class_Vector2_operator_dif_Vector2:
  588. .. rst-class:: classref-operator
  589. :ref:`Vector2<class_Vector2>` **operator -** **(** :ref:`Vector2<class_Vector2>` right **)**
  590. Subtracts each component of the **Vector2** by the components of the given **Vector2**.
  591. ::
  592. print(Vector2(10, 20) - Vector2(3, 4)) # Prints "(7, 16)"
  593. .. rst-class:: classref-item-separator
  594. ----
  595. .. _class_Vector2_operator_div_Vector2:
  596. .. rst-class:: classref-operator
  597. :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`Vector2<class_Vector2>` right **)**
  598. Divides each component of the **Vector2** by the components of the given **Vector2**.
  599. ::
  600. print(Vector2(10, 20) / Vector2(2, 5)) # Prints "(5, 4)"
  601. .. rst-class:: classref-item-separator
  602. ----
  603. .. _class_Vector2_operator_div_float:
  604. .. rst-class:: classref-operator
  605. :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`float<class_float>` right **)**
  606. Divides each component of the **Vector2** by the given :ref:`float<class_float>`.
  607. .. rst-class:: classref-item-separator
  608. ----
  609. .. _class_Vector2_operator_div_int:
  610. .. rst-class:: classref-operator
  611. :ref:`Vector2<class_Vector2>` **operator /** **(** :ref:`int<class_int>` right **)**
  612. Divides each component of the **Vector2** by the given :ref:`int<class_int>`.
  613. .. rst-class:: classref-item-separator
  614. ----
  615. .. _class_Vector2_operator_lt_Vector2:
  616. .. rst-class:: classref-operator
  617. :ref:`bool<class_bool>` **operator <** **(** :ref:`Vector2<class_Vector2>` right **)**
  618. 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.
  619. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  620. .. rst-class:: classref-item-separator
  621. ----
  622. .. _class_Vector2_operator_lte_Vector2:
  623. .. rst-class:: classref-operator
  624. :ref:`bool<class_bool>` **operator <=** **(** :ref:`Vector2<class_Vector2>` right **)**
  625. 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.
  626. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  627. .. rst-class:: classref-item-separator
  628. ----
  629. .. _class_Vector2_operator_eq_Vector2:
  630. .. rst-class:: classref-operator
  631. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Vector2<class_Vector2>` right **)**
  632. Returns ``true`` if the vectors are exactly equal.
  633. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>` instead, which is more reliable.
  634. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  635. .. rst-class:: classref-item-separator
  636. ----
  637. .. _class_Vector2_operator_gt_Vector2:
  638. .. rst-class:: classref-operator
  639. :ref:`bool<class_bool>` **operator >** **(** :ref:`Vector2<class_Vector2>` right **)**
  640. 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.
  641. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  642. .. rst-class:: classref-item-separator
  643. ----
  644. .. _class_Vector2_operator_gte_Vector2:
  645. .. rst-class:: classref-operator
  646. :ref:`bool<class_bool>` **operator >=** **(** :ref:`Vector2<class_Vector2>` right **)**
  647. 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.
  648. \ **Note:** Vectors with :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` elements don't behave the same as other vectors. Therefore, the results from this operator may not be accurate if NaNs are included.
  649. .. rst-class:: classref-item-separator
  650. ----
  651. .. _class_Vector2_operator_idx_int:
  652. .. rst-class:: classref-operator
  653. :ref:`float<class_float>` **operator []** **(** :ref:`int<class_int>` index **)**
  654. Access vector components using their ``index``. ``v[0]`` is equivalent to ``v.x``, and ``v[1]`` is equivalent to ``v.y``.
  655. .. rst-class:: classref-item-separator
  656. ----
  657. .. _class_Vector2_operator_unplus:
  658. .. rst-class:: classref-operator
  659. :ref:`Vector2<class_Vector2>` **operator unary+** **(** **)**
  660. Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
  661. .. rst-class:: classref-item-separator
  662. ----
  663. .. _class_Vector2_operator_unminus:
  664. .. rst-class:: classref-operator
  665. :ref:`Vector2<class_Vector2>` **operator unary-** **(** **)**
  666. 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.
  667. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  668. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  669. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  670. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  671. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  672. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  673. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`