class_collisionobject2d.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the CollisionObject2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_CollisionObject2D:
  6. CollisionObject2D
  7. =================
  8. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`Area2D<class_Area2D>`, :ref:`PhysicsBody2D<class_PhysicsBody2D>`
  10. Base node for 2D collision objects.
  11. Description
  12. -----------
  13. CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision :ref:`Shape2D<class_Shape2D>`\ s. Each shape must be assigned to a *shape owner*. The CollisionObject2D can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the ``shape_owner_*`` methods.
  14. **Note:** Only collisions between objects within the same canvas (:ref:`Viewport<class_Viewport>` canvas or :ref:`CanvasLayer<class_CanvasLayer>`) are supported. The behavior of collisions between objects in different canvases is undefined.
  15. Properties
  16. ----------
  17. +-------------------------+--------------------------------------------------------------------------+----------+
  18. | :ref:`int<class_int>` | :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>` | ``1`` |
  19. +-------------------------+--------------------------------------------------------------------------+----------+
  20. | :ref:`int<class_int>` | :ref:`collision_mask<class_CollisionObject2D_property_collision_mask>` | ``1`` |
  21. +-------------------------+--------------------------------------------------------------------------+----------+
  22. | :ref:`bool<class_bool>` | :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` | ``true`` |
  23. +-------------------------+--------------------------------------------------------------------------+----------+
  24. Methods
  25. -------
  26. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`_input_event<class_CollisionObject2D_method__input_event>` **(** :ref:`Object<class_Object>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)** |virtual| |
  28. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`create_shape_owner<class_CollisionObject2D_method_create_shape_owner>` **(** :ref:`Object<class_Object>` owner **)** |
  30. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_bit<class_CollisionObject2D_method_get_collision_layer_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  32. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_CollisionObject2D_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  34. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`RID<class_RID>` | :ref:`get_rid<class_CollisionObject2D_method_get_rid>` **(** **)** |const| |
  36. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_shape_owner_one_way_collision_margin<class_CollisionObject2D_method_get_shape_owner_one_way_collision_margin>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  38. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Array<class_Array>` | :ref:`get_shape_owners<class_CollisionObject2D_method_get_shape_owners>` **(** **)** |
  40. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_disabled<class_CollisionObject2D_method_is_shape_owner_disabled>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  42. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_one_way_collision_enabled<class_CollisionObject2D_method_is_shape_owner_one_way_collision_enabled>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  44. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`remove_shape_owner<class_CollisionObject2D_method_remove_shape_owner>` **(** :ref:`int<class_int>` owner_id **)** |
  46. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`set_collision_layer_bit<class_CollisionObject2D_method_set_collision_layer_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  48. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`set_collision_mask_bit<class_CollisionObject2D_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  50. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`shape_find_owner<class_CollisionObject2D_method_shape_find_owner>` **(** :ref:`int<class_int>` shape_index **)** |const| |
  52. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`shape_owner_add_shape<class_CollisionObject2D_method_shape_owner_add_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`Shape2D<class_Shape2D>` shape **)** |
  54. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`shape_owner_clear_shapes<class_CollisionObject2D_method_shape_owner_clear_shapes>` **(** :ref:`int<class_int>` owner_id **)** |
  56. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Object<class_Object>` | :ref:`shape_owner_get_owner<class_CollisionObject2D_method_shape_owner_get_owner>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  58. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Shape2D<class_Shape2D>` | :ref:`shape_owner_get_shape<class_CollisionObject2D_method_shape_owner_get_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const| |
  60. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_count<class_CollisionObject2D_method_shape_owner_get_shape_count>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  62. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_index<class_CollisionObject2D_method_shape_owner_get_shape_index>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const| |
  64. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Transform2D<class_Transform2D>` | :ref:`shape_owner_get_transform<class_CollisionObject2D_method_shape_owner_get_transform>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  66. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`shape_owner_remove_shape<class_CollisionObject2D_method_shape_owner_remove_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |
  68. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`shape_owner_set_disabled<class_CollisionObject2D_method_shape_owner_set_disabled>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)** |
  70. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`shape_owner_set_one_way_collision<class_CollisionObject2D_method_shape_owner_set_one_way_collision>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` enable **)** |
  72. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`shape_owner_set_one_way_collision_margin<class_CollisionObject2D_method_shape_owner_set_one_way_collision_margin>` **(** :ref:`int<class_int>` owner_id, :ref:`float<class_float>` margin **)** |
  74. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`shape_owner_set_transform<class_CollisionObject2D_method_shape_owner_set_transform>` **(** :ref:`int<class_int>` owner_id, :ref:`Transform2D<class_Transform2D>` transform **)** |
  76. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. Signals
  78. -------
  79. .. _class_CollisionObject2D_signal_input_event:
  80. - **input_event** **(** :ref:`Node<class_Node>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)**
  81. Emitted when an input event occurs. Requires :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` to be ``true`` and at least one ``collision_layer`` bit to be set. See :ref:`_input_event<class_CollisionObject2D_method__input_event>` for details.
  82. ----
  83. .. _class_CollisionObject2D_signal_mouse_entered:
  84. - **mouse_entered** **(** **)**
  85. Emitted when the mouse pointer enters any of this object's shapes. Requires :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` to be ``true`` and at least one ``collision_layer`` bit to be set.
  86. ----
  87. .. _class_CollisionObject2D_signal_mouse_exited:
  88. - **mouse_exited** **(** **)**
  89. Emitted when the mouse pointer exits all this object's shapes. Requires :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` to be ``true`` and at least one ``collision_layer`` bit to be set.
  90. Property Descriptions
  91. ---------------------
  92. .. _class_CollisionObject2D_property_collision_layer:
  93. - :ref:`int<class_int>` **collision_layer**
  94. +-----------+----------------------------+
  95. | *Default* | ``1`` |
  96. +-----------+----------------------------+
  97. | *Setter* | set_collision_layer(value) |
  98. +-----------+----------------------------+
  99. | *Getter* | get_collision_layer() |
  100. +-----------+----------------------------+
  101. The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also :ref:`collision_mask<class_CollisionObject2D_property_collision_mask>`.
  102. **Note:** A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See `Collision layers and masks <https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  103. ----
  104. .. _class_CollisionObject2D_property_collision_mask:
  105. - :ref:`int<class_int>` **collision_mask**
  106. +-----------+---------------------------+
  107. | *Default* | ``1`` |
  108. +-----------+---------------------------+
  109. | *Setter* | set_collision_mask(value) |
  110. +-----------+---------------------------+
  111. | *Getter* | get_collision_mask() |
  112. +-----------+---------------------------+
  113. The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>`.
  114. **Note:** A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See `Collision layers and masks <https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  115. ----
  116. .. _class_CollisionObject2D_property_input_pickable:
  117. - :ref:`bool<class_bool>` **input_pickable**
  118. +-----------+---------------------+
  119. | *Default* | ``true`` |
  120. +-----------+---------------------+
  121. | *Setter* | set_pickable(value) |
  122. +-----------+---------------------+
  123. | *Getter* | is_pickable() |
  124. +-----------+---------------------+
  125. If ``true``, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>` bit to be set.
  126. Method Descriptions
  127. -------------------
  128. .. _class_CollisionObject2D_method__input_event:
  129. - void **_input_event** **(** :ref:`Object<class_Object>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)** |virtual|
  130. Accepts unhandled :ref:`InputEvent<class_InputEvent>`\ s. Requires :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` to be ``true``. ``shape_idx`` is the child index of the clicked :ref:`Shape2D<class_Shape2D>`. Connect to the ``input_event`` signal to easily pick up these events.
  131. ----
  132. .. _class_CollisionObject2D_method_create_shape_owner:
  133. - :ref:`int<class_int>` **create_shape_owner** **(** :ref:`Object<class_Object>` owner **)**
  134. Creates a new shape owner for the given object. Returns ``owner_id`` of the new owner for future reference.
  135. ----
  136. .. _class_CollisionObject2D_method_get_collision_layer_bit:
  137. - :ref:`bool<class_bool>` **get_collision_layer_bit** **(** :ref:`int<class_int>` bit **)** |const|
  138. Returns whether or not the specified ``bit`` of the :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>` is set.
  139. ----
  140. .. _class_CollisionObject2D_method_get_collision_mask_bit:
  141. - :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** |const|
  142. Returns whether or not the specified ``bit`` of the :ref:`collision_mask<class_CollisionObject2D_property_collision_mask>` is set.
  143. ----
  144. .. _class_CollisionObject2D_method_get_rid:
  145. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  146. Returns the object's :ref:`RID<class_RID>`.
  147. ----
  148. .. _class_CollisionObject2D_method_get_shape_owner_one_way_collision_margin:
  149. - :ref:`float<class_float>` **get_shape_owner_one_way_collision_margin** **(** :ref:`int<class_int>` owner_id **)** |const|
  150. Returns the ``one_way_collision_margin`` of the shape owner identified by given ``owner_id``.
  151. ----
  152. .. _class_CollisionObject2D_method_get_shape_owners:
  153. - :ref:`Array<class_Array>` **get_shape_owners** **(** **)**
  154. Returns an :ref:`Array<class_Array>` of ``owner_id`` identifiers. You can use these ids in other methods that take ``owner_id`` as an argument.
  155. ----
  156. .. _class_CollisionObject2D_method_is_shape_owner_disabled:
  157. - :ref:`bool<class_bool>` **is_shape_owner_disabled** **(** :ref:`int<class_int>` owner_id **)** |const|
  158. If ``true``, the shape owner and its shapes are disabled.
  159. ----
  160. .. _class_CollisionObject2D_method_is_shape_owner_one_way_collision_enabled:
  161. - :ref:`bool<class_bool>` **is_shape_owner_one_way_collision_enabled** **(** :ref:`int<class_int>` owner_id **)** |const|
  162. Returns ``true`` if collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s.
  163. ----
  164. .. _class_CollisionObject2D_method_remove_shape_owner:
  165. - void **remove_shape_owner** **(** :ref:`int<class_int>` owner_id **)**
  166. Removes the given shape owner.
  167. ----
  168. .. _class_CollisionObject2D_method_set_collision_layer_bit:
  169. - void **set_collision_layer_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  170. If ``value`` is ``true``, sets the specified ``bit`` in the the :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>`.
  171. If ``value`` is ``false``, clears the specified ``bit`` in the the :ref:`collision_layer<class_CollisionObject2D_property_collision_layer>`.
  172. ----
  173. .. _class_CollisionObject2D_method_set_collision_mask_bit:
  174. - void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  175. If ``value`` is ``true``, sets the specified ``bit`` in the the :ref:`collision_mask<class_CollisionObject2D_property_collision_mask>`.
  176. If ``value`` is ``false``, clears the specified ``bit`` in the the :ref:`collision_mask<class_CollisionObject2D_property_collision_mask>`.
  177. ----
  178. .. _class_CollisionObject2D_method_shape_find_owner:
  179. - :ref:`int<class_int>` **shape_find_owner** **(** :ref:`int<class_int>` shape_index **)** |const|
  180. Returns the ``owner_id`` of the given shape.
  181. ----
  182. .. _class_CollisionObject2D_method_shape_owner_add_shape:
  183. - void **shape_owner_add_shape** **(** :ref:`int<class_int>` owner_id, :ref:`Shape2D<class_Shape2D>` shape **)**
  184. Adds a :ref:`Shape2D<class_Shape2D>` to the shape owner.
  185. ----
  186. .. _class_CollisionObject2D_method_shape_owner_clear_shapes:
  187. - void **shape_owner_clear_shapes** **(** :ref:`int<class_int>` owner_id **)**
  188. Removes all shapes from the shape owner.
  189. ----
  190. .. _class_CollisionObject2D_method_shape_owner_get_owner:
  191. - :ref:`Object<class_Object>` **shape_owner_get_owner** **(** :ref:`int<class_int>` owner_id **)** |const|
  192. Returns the parent object of the given shape owner.
  193. ----
  194. .. _class_CollisionObject2D_method_shape_owner_get_shape:
  195. - :ref:`Shape2D<class_Shape2D>` **shape_owner_get_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  196. Returns the :ref:`Shape2D<class_Shape2D>` with the given id from the given shape owner.
  197. ----
  198. .. _class_CollisionObject2D_method_shape_owner_get_shape_count:
  199. - :ref:`int<class_int>` **shape_owner_get_shape_count** **(** :ref:`int<class_int>` owner_id **)** |const|
  200. Returns the number of shapes the given shape owner contains.
  201. ----
  202. .. _class_CollisionObject2D_method_shape_owner_get_shape_index:
  203. - :ref:`int<class_int>` **shape_owner_get_shape_index** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  204. Returns the child index of the :ref:`Shape2D<class_Shape2D>` with the given id from the given shape owner.
  205. ----
  206. .. _class_CollisionObject2D_method_shape_owner_get_transform:
  207. - :ref:`Transform2D<class_Transform2D>` **shape_owner_get_transform** **(** :ref:`int<class_int>` owner_id **)** |const|
  208. Returns the shape owner's :ref:`Transform2D<class_Transform2D>`.
  209. ----
  210. .. _class_CollisionObject2D_method_shape_owner_remove_shape:
  211. - void **shape_owner_remove_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)**
  212. Removes a shape from the given shape owner.
  213. ----
  214. .. _class_CollisionObject2D_method_shape_owner_set_disabled:
  215. - void **shape_owner_set_disabled** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)**
  216. If ``true``, disables the given shape owner.
  217. ----
  218. .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision:
  219. - void **shape_owner_set_one_way_collision** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` enable **)**
  220. If ``enable`` is ``true``, collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s.
  221. ----
  222. .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision_margin:
  223. - void **shape_owner_set_one_way_collision_margin** **(** :ref:`int<class_int>` owner_id, :ref:`float<class_float>` margin **)**
  224. Sets the ``one_way_collision_margin`` of the shape owner identified by given ``owner_id`` to ``margin`` pixels.
  225. ----
  226. .. _class_CollisionObject2D_method_shape_owner_set_transform:
  227. - void **shape_owner_set_transform** **(** :ref:`int<class_int>` owner_id, :ref:`Transform2D<class_Transform2D>` transform **)**
  228. Sets the :ref:`Transform2D<class_Transform2D>` of the given shape owner.
  229. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  230. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  231. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`