class_shapecast2d.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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/ShapeCast2D.xml.
  6. .. _class_ShapeCast2D:
  7. ShapeCast2D
  8. ===========
  9. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Node for physics collision sweep and immediate overlap queries. Similar to the :ref:`RayCast2D<class_RayCast2D>` node.
  11. Description
  12. -----------
  13. Shape casting allows to detect collision objects by sweeping the :ref:`shape<class_ShapeCast2D_property_shape>` along the cast direction determined by :ref:`target_position<class_ShapeCast2D_property_target_position>` (useful for things like beam weapons).
  14. Immediate collision overlaps can be done with the :ref:`target_position<class_ShapeCast2D_property_target_position>` set to ``Vector2(0, 0)`` and by calling :ref:`force_shapecast_update<class_ShapeCast2D_method_force_shapecast_update>` within the same **physics_frame**. This also helps to overcome some limitations of :ref:`Area2D<class_Area2D>` when used as a continuous detection area, often requiring waiting a couple of frames before collision information is available to :ref:`Area2D<class_Area2D>` nodes, and when using the signals creates unnecessary complexity.
  15. The node can detect multiple collision objects, but usually the first detected collision
  16. \ **Note:** shape casting is more computationally expensive compared to ray casting.
  17. Properties
  18. ----------
  19. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  20. | :ref:`bool<class_bool>` | :ref:`collide_with_areas<class_ShapeCast2D_property_collide_with_areas>` | ``false`` |
  21. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  22. | :ref:`bool<class_bool>` | :ref:`collide_with_bodies<class_ShapeCast2D_property_collide_with_bodies>` | ``true`` |
  23. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  24. | :ref:`int<class_int>` | :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>` | ``1`` |
  25. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  26. | :ref:`Array<class_Array>` | :ref:`collision_result<class_ShapeCast2D_property_collision_result>` | ``[]`` |
  27. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  28. | :ref:`bool<class_bool>` | :ref:`enabled<class_ShapeCast2D_property_enabled>` | ``true`` |
  29. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  30. | :ref:`bool<class_bool>` | :ref:`exclude_parent<class_ShapeCast2D_property_exclude_parent>` | ``true`` |
  31. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  32. | :ref:`float<class_float>` | :ref:`margin<class_ShapeCast2D_property_margin>` | ``0.0`` |
  33. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  34. | :ref:`int<class_int>` | :ref:`max_results<class_ShapeCast2D_property_max_results>` | ``32`` |
  35. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  36. | :ref:`Shape2D<class_Shape2D>` | :ref:`shape<class_ShapeCast2D_property_shape>` | |
  37. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  38. | :ref:`Vector2<class_Vector2>` | :ref:`target_position<class_ShapeCast2D_property_target_position>` | ``Vector2(0, 50)`` |
  39. +-------------------------------+----------------------------------------------------------------------------+--------------------+
  40. Methods
  41. -------
  42. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`add_exception<class_ShapeCast2D_method_add_exception>` **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)** |
  44. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`add_exception_rid<class_ShapeCast2D_method_add_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  46. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`clear_exceptions<class_ShapeCast2D_method_clear_exceptions>` **(** **)** |
  48. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`force_shapecast_update<class_ShapeCast2D_method_force_shapecast_update>` **(** **)** |
  50. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`float<class_float>` | :ref:`get_closest_collision_safe_fraction<class_ShapeCast2D_method_get_closest_collision_safe_fraction>` **(** **)** |const| |
  52. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`get_closest_collision_unsafe_fraction<class_ShapeCast2D_method_get_closest_collision_unsafe_fraction>` **(** **)** |const| |
  54. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Object<class_Object>` | :ref:`get_collider<class_ShapeCast2D_method_get_collider>` **(** :ref:`int<class_int>` index **)** |const| |
  56. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_collider_shape<class_ShapeCast2D_method_get_collider_shape>` **(** :ref:`int<class_int>` index **)** |const| |
  58. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`int<class_int>` | :ref:`get_collision_count<class_ShapeCast2D_method_get_collision_count>` **(** **)** |const| |
  60. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_value<class_ShapeCast2D_method_get_collision_mask_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  62. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_normal<class_ShapeCast2D_method_get_collision_normal>` **(** :ref:`int<class_int>` index **)** |const| |
  64. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_point<class_ShapeCast2D_method_get_collision_point>` **(** :ref:`int<class_int>` index **)** |const| |
  66. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` **(** **)** |const| |
  68. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`remove_exception<class_ShapeCast2D_method_remove_exception>` **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)** |
  70. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`remove_exception_rid<class_ShapeCast2D_method_remove_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  72. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_collision_mask_value<class_ShapeCast2D_method_set_collision_mask_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  74. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. Property Descriptions
  76. ---------------------
  77. .. _class_ShapeCast2D_property_collide_with_areas:
  78. - :ref:`bool<class_bool>` **collide_with_areas**
  79. +-----------+---------------------------------+
  80. | *Default* | ``false`` |
  81. +-----------+---------------------------------+
  82. | *Setter* | set_collide_with_areas(value) |
  83. +-----------+---------------------------------+
  84. | *Getter* | is_collide_with_areas_enabled() |
  85. +-----------+---------------------------------+
  86. If ``true``, collision with :ref:`Area2D<class_Area2D>`\ s will be reported.
  87. ----
  88. .. _class_ShapeCast2D_property_collide_with_bodies:
  89. - :ref:`bool<class_bool>` **collide_with_bodies**
  90. +-----------+----------------------------------+
  91. | *Default* | ``true`` |
  92. +-----------+----------------------------------+
  93. | *Setter* | set_collide_with_bodies(value) |
  94. +-----------+----------------------------------+
  95. | *Getter* | is_collide_with_bodies_enabled() |
  96. +-----------+----------------------------------+
  97. If ``true``, collision with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s will be reported.
  98. ----
  99. .. _class_ShapeCast2D_property_collision_mask:
  100. - :ref:`int<class_int>` **collision_mask**
  101. +-----------+---------------------------+
  102. | *Default* | ``1`` |
  103. +-----------+---------------------------+
  104. | *Setter* | set_collision_mask(value) |
  105. +-----------+---------------------------+
  106. | *Getter* | get_collision_mask() |
  107. +-----------+---------------------------+
  108. The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
  109. ----
  110. .. _class_ShapeCast2D_property_collision_result:
  111. - :ref:`Array<class_Array>` **collision_result**
  112. +-----------+--------+
  113. | *Default* | ``[]`` |
  114. +-----------+--------+
  115. A complete collision information. The data returned is the same as in the :ref:`PhysicsDirectSpaceState2D.get_rest_info<class_PhysicsDirectSpaceState2D_method_get_rest_info>` method.
  116. ----
  117. .. _class_ShapeCast2D_property_enabled:
  118. - :ref:`bool<class_bool>` **enabled**
  119. +-----------+--------------------+
  120. | *Default* | ``true`` |
  121. +-----------+--------------------+
  122. | *Setter* | set_enabled(value) |
  123. +-----------+--------------------+
  124. | *Getter* | is_enabled() |
  125. +-----------+--------------------+
  126. If ``true``, collisions will be reported.
  127. ----
  128. .. _class_ShapeCast2D_property_exclude_parent:
  129. - :ref:`bool<class_bool>` **exclude_parent**
  130. +-----------+--------------------------------+
  131. | *Default* | ``true`` |
  132. +-----------+--------------------------------+
  133. | *Setter* | set_exclude_parent_body(value) |
  134. +-----------+--------------------------------+
  135. | *Getter* | get_exclude_parent_body() |
  136. +-----------+--------------------------------+
  137. If ``true``, the parent node will be excluded from collision detection.
  138. ----
  139. .. _class_ShapeCast2D_property_margin:
  140. - :ref:`float<class_float>` **margin**
  141. +-----------+-------------------+
  142. | *Default* | ``0.0`` |
  143. +-----------+-------------------+
  144. | *Setter* | set_margin(value) |
  145. +-----------+-------------------+
  146. | *Getter* | get_margin() |
  147. +-----------+-------------------+
  148. The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
  149. ----
  150. .. _class_ShapeCast2D_property_max_results:
  151. - :ref:`int<class_int>` **max_results**
  152. +-----------+------------------------+
  153. | *Default* | ``32`` |
  154. +-----------+------------------------+
  155. | *Setter* | set_max_results(value) |
  156. +-----------+------------------------+
  157. | *Getter* | get_max_results() |
  158. +-----------+------------------------+
  159. The number of intersections can be limited with this parameter, to reduce the processing time.
  160. ----
  161. .. _class_ShapeCast2D_property_shape:
  162. - :ref:`Shape2D<class_Shape2D>` **shape**
  163. +----------+------------------+
  164. | *Setter* | set_shape(value) |
  165. +----------+------------------+
  166. | *Getter* | get_shape() |
  167. +----------+------------------+
  168. Any :ref:`Shape2D<class_Shape2D>` derived shape used for collision queries.
  169. ----
  170. .. _class_ShapeCast2D_property_target_position:
  171. - :ref:`Vector2<class_Vector2>` **target_position**
  172. +-----------+----------------------------+
  173. | *Default* | ``Vector2(0, 50)`` |
  174. +-----------+----------------------------+
  175. | *Setter* | set_target_position(value) |
  176. +-----------+----------------------------+
  177. | *Getter* | get_target_position() |
  178. +-----------+----------------------------+
  179. The shape's destination point, relative to this node's ``position``.
  180. Method Descriptions
  181. -------------------
  182. .. _class_ShapeCast2D_method_add_exception:
  183. - void **add_exception** **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)**
  184. Adds a collision exception so the shape does not report collisions with the specified :ref:`CollisionObject2D<class_CollisionObject2D>` node.
  185. ----
  186. .. _class_ShapeCast2D_method_add_exception_rid:
  187. - void **add_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  188. Adds a collision exception so the shape does not report collisions with the specified :ref:`RID<class_RID>`.
  189. ----
  190. .. _class_ShapeCast2D_method_clear_exceptions:
  191. - void **clear_exceptions** **(** **)**
  192. Removes all collision exceptions for this shape.
  193. ----
  194. .. _class_ShapeCast2D_method_force_shapecast_update:
  195. - void **force_shapecast_update** **(** **)**
  196. Updates the collision information for the shape. Use this method to update the collision information immediately instead of waiting for the next ``_physics_process`` call, for example if the shape or its parent has changed state.
  197. \ **Note:** ``enabled == true`` is not required for this to work.
  198. ----
  199. .. _class_ShapeCast2D_method_get_closest_collision_safe_fraction:
  200. - :ref:`float<class_float>` **get_closest_collision_safe_fraction** **(** **)** |const|
  201. The fraction of the motion (between 0 and 1) of how far the shape can move without triggering a collision. The motion is determined by :ref:`target_position<class_ShapeCast2D_property_target_position>`.
  202. ----
  203. .. _class_ShapeCast2D_method_get_closest_collision_unsafe_fraction:
  204. - :ref:`float<class_float>` **get_closest_collision_unsafe_fraction** **(** **)** |const|
  205. The fraction of the motion (between 0 and 1) when the shape triggers a collision. The motion is determined by :ref:`target_position<class_ShapeCast2D_property_target_position>`.
  206. ----
  207. .. _class_ShapeCast2D_method_get_collider:
  208. - :ref:`Object<class_Object>` **get_collider** **(** :ref:`int<class_int>` index **)** |const|
  209. Returns the :ref:`Object<class_Object>` of one of the multiple collisions at ``index``, or ``null`` if no object is intersecting the shape (i.e. :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` returns ``false``).
  210. ----
  211. .. _class_ShapeCast2D_method_get_collider_shape:
  212. - :ref:`int<class_int>` **get_collider_shape** **(** :ref:`int<class_int>` index **)** |const|
  213. Returns the shape ID of one of the multiple collisions at ``index`` that the shape intersects, or ``0`` if no object is intersecting the shape (i.e. :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` returns ``false``).
  214. ----
  215. .. _class_ShapeCast2D_method_get_collision_count:
  216. - :ref:`int<class_int>` **get_collision_count** **(** **)** |const|
  217. The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by :ref:`get_collider<class_ShapeCast2D_method_get_collider>`, :ref:`get_collider_shape<class_ShapeCast2D_method_get_collider_shape>`, :ref:`get_collision_point<class_ShapeCast2D_method_get_collision_point>`, and :ref:`get_collision_normal<class_ShapeCast2D_method_get_collision_normal>` methods.
  218. ----
  219. .. _class_ShapeCast2D_method_get_collision_mask_value:
  220. - :ref:`bool<class_bool>` **get_collision_mask_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  221. Returns whether or not the specified layer of the :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>` is enabled, given a ``layer_number`` between 1 and 32.
  222. ----
  223. .. _class_ShapeCast2D_method_get_collision_normal:
  224. - :ref:`Vector2<class_Vector2>` **get_collision_normal** **(** :ref:`int<class_int>` index **)** |const|
  225. Returns the normal containing one of the multiple collisions at ``index`` of the intersecting object.
  226. ----
  227. .. _class_ShapeCast2D_method_get_collision_point:
  228. - :ref:`Vector2<class_Vector2>` **get_collision_point** **(** :ref:`int<class_int>` index **)** |const|
  229. Returns the collision point containing one of the multiple collisions at ``index`` at which the shape intersects the object.
  230. \ **Note:** this point is in the **global** coordinate system.
  231. ----
  232. .. _class_ShapeCast2D_method_is_colliding:
  233. - :ref:`bool<class_bool>` **is_colliding** **(** **)** |const|
  234. Returns whether any object is intersecting with the shape's vector (considering the vector length).
  235. ----
  236. .. _class_ShapeCast2D_method_remove_exception:
  237. - void **remove_exception** **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)**
  238. Removes a collision exception so the shape does report collisions with the specified :ref:`CollisionObject2D<class_CollisionObject2D>` node.
  239. ----
  240. .. _class_ShapeCast2D_method_remove_exception_rid:
  241. - void **remove_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  242. Removes a collision exception so the shape does report collisions with the specified :ref:`RID<class_RID>`.
  243. ----
  244. .. _class_ShapeCast2D_method_set_collision_mask_value:
  245. - void **set_collision_mask_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  246. Based on ``value``, enables or disables the specified layer in the :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>`, given a ``layer_number`` between 1 and 32.
  247. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  248. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  249. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  250. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  251. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  252. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`