class_collisionobject.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 CollisionObject.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_CollisionObject:
  6. CollisionObject
  7. ===============
  8. **Inherits:** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`Area<class_Area>`, :ref:`PhysicsBody<class_PhysicsBody>`
  10. Base node for collision objects.
  11. Description
  12. -----------
  13. CollisionObject is the base class for physics objects. It can hold any number of collision :ref:`Shape<class_Shape>`\ s. Each shape must be assigned to a *shape owner*. The CollisionObject 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. Properties
  15. ----------
  16. +-------------------------+------------------------------------------------------------------------------------+-----------+
  17. | :ref:`int<class_int>` | :ref:`collision_layer<class_CollisionObject_property_collision_layer>` | ``1`` |
  18. +-------------------------+------------------------------------------------------------------------------------+-----------+
  19. | :ref:`int<class_int>` | :ref:`collision_mask<class_CollisionObject_property_collision_mask>` | ``1`` |
  20. +-------------------------+------------------------------------------------------------------------------------+-----------+
  21. | :ref:`bool<class_bool>` | :ref:`input_capture_on_drag<class_CollisionObject_property_input_capture_on_drag>` | ``false`` |
  22. +-------------------------+------------------------------------------------------------------------------------+-----------+
  23. | :ref:`bool<class_bool>` | :ref:`input_ray_pickable<class_CollisionObject_property_input_ray_pickable>` | ``true`` |
  24. +-------------------------+------------------------------------------------------------------------------------+-----------+
  25. Methods
  26. -------
  27. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`_input_event<class_CollisionObject_method__input_event>` **(** :ref:`Object<class_Object>` camera, :ref:`InputEvent<class_InputEvent>` event, :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` normal, :ref:`int<class_int>` shape_idx **)** |virtual| |
  29. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`int<class_int>` | :ref:`create_shape_owner<class_CollisionObject_method_create_shape_owner>` **(** :ref:`Object<class_Object>` owner **)** |
  31. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_bit<class_CollisionObject_method_get_collision_layer_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  33. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_CollisionObject_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  35. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`RID<class_RID>` | :ref:`get_rid<class_CollisionObject_method_get_rid>` **(** **)** |const| |
  37. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Array<class_Array>` | :ref:`get_shape_owners<class_CollisionObject_method_get_shape_owners>` **(** **)** |
  39. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_disabled<class_CollisionObject_method_is_shape_owner_disabled>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  41. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`remove_shape_owner<class_CollisionObject_method_remove_shape_owner>` **(** :ref:`int<class_int>` owner_id **)** |
  43. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`set_collision_layer_bit<class_CollisionObject_method_set_collision_layer_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  45. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_collision_mask_bit<class_CollisionObject_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  47. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`shape_find_owner<class_CollisionObject_method_shape_find_owner>` **(** :ref:`int<class_int>` shape_index **)** |const| |
  49. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`shape_owner_add_shape<class_CollisionObject_method_shape_owner_add_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`Shape<class_Shape>` shape **)** |
  51. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`shape_owner_clear_shapes<class_CollisionObject_method_shape_owner_clear_shapes>` **(** :ref:`int<class_int>` owner_id **)** |
  53. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Object<class_Object>` | :ref:`shape_owner_get_owner<class_CollisionObject_method_shape_owner_get_owner>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  55. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Shape<class_Shape>` | :ref:`shape_owner_get_shape<class_CollisionObject_method_shape_owner_get_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const| |
  57. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_count<class_CollisionObject_method_shape_owner_get_shape_count>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  59. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_index<class_CollisionObject_method_shape_owner_get_shape_index>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const| |
  61. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Transform<class_Transform>` | :ref:`shape_owner_get_transform<class_CollisionObject_method_shape_owner_get_transform>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  63. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`shape_owner_remove_shape<class_CollisionObject_method_shape_owner_remove_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |
  65. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`shape_owner_set_disabled<class_CollisionObject_method_shape_owner_set_disabled>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)** |
  67. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`shape_owner_set_transform<class_CollisionObject_method_shape_owner_set_transform>` **(** :ref:`int<class_int>` owner_id, :ref:`Transform<class_Transform>` transform **)** |
  69. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. Signals
  71. -------
  72. .. _class_CollisionObject_signal_input_event:
  73. - **input_event** **(** :ref:`Node<class_Node>` camera, :ref:`InputEvent<class_InputEvent>` event, :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` normal, :ref:`int<class_int>` shape_idx **)**
  74. Emitted when the object receives an unhandled :ref:`InputEvent<class_InputEvent>`. ``position`` is the location in world space of the mouse pointer on the surface of the shape with index ``shape_idx`` and ``normal`` is the normal vector of the surface at that point.
  75. ----
  76. .. _class_CollisionObject_signal_mouse_entered:
  77. - **mouse_entered** **(** **)**
  78. Emitted when the mouse pointer enters any of this object's shapes.
  79. ----
  80. .. _class_CollisionObject_signal_mouse_exited:
  81. - **mouse_exited** **(** **)**
  82. Emitted when the mouse pointer exits all this object's shapes.
  83. Property Descriptions
  84. ---------------------
  85. .. _class_CollisionObject_property_collision_layer:
  86. - :ref:`int<class_int>` **collision_layer**
  87. +-----------+----------------------------+
  88. | *Default* | ``1`` |
  89. +-----------+----------------------------+
  90. | *Setter* | set_collision_layer(value) |
  91. +-----------+----------------------------+
  92. | *Getter* | get_collision_layer() |
  93. +-----------+----------------------------+
  94. The physics layers this CollisionObject3D is in. Collision objects can exist in one or more of 32 different layers. See also :ref:`collision_mask<class_CollisionObject_property_collision_mask>`.
  95. **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.
  96. ----
  97. .. _class_CollisionObject_property_collision_mask:
  98. - :ref:`int<class_int>` **collision_mask**
  99. +-----------+---------------------------+
  100. | *Default* | ``1`` |
  101. +-----------+---------------------------+
  102. | *Setter* | set_collision_mask(value) |
  103. +-----------+---------------------------+
  104. | *Getter* | get_collision_mask() |
  105. +-----------+---------------------------+
  106. The physics layers this CollisionObject3D scans. Collision objects can scan one or more of 32 different layers. See also :ref:`collision_layer<class_CollisionObject_property_collision_layer>`.
  107. **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.
  108. ----
  109. .. _class_CollisionObject_property_input_capture_on_drag:
  110. - :ref:`bool<class_bool>` **input_capture_on_drag**
  111. +-----------+----------------------------------+
  112. | *Default* | ``false`` |
  113. +-----------+----------------------------------+
  114. | *Setter* | set_capture_input_on_drag(value) |
  115. +-----------+----------------------------------+
  116. | *Getter* | get_capture_input_on_drag() |
  117. +-----------+----------------------------------+
  118. If ``true``, the ``CollisionObject`` will continue to receive input events as the mouse is dragged across its shapes.
  119. ----
  120. .. _class_CollisionObject_property_input_ray_pickable:
  121. - :ref:`bool<class_bool>` **input_ray_pickable**
  122. +-----------+-------------------------+
  123. | *Default* | ``true`` |
  124. +-----------+-------------------------+
  125. | *Setter* | set_ray_pickable(value) |
  126. +-----------+-------------------------+
  127. | *Getter* | is_ray_pickable() |
  128. +-----------+-------------------------+
  129. 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_CollisionObject_property_collision_layer>` bit to be set.
  130. Method Descriptions
  131. -------------------
  132. .. _class_CollisionObject_method__input_event:
  133. - void **_input_event** **(** :ref:`Object<class_Object>` camera, :ref:`InputEvent<class_InputEvent>` event, :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` normal, :ref:`int<class_int>` shape_idx **)** |virtual|
  134. Receives unhandled :ref:`InputEvent<class_InputEvent>`\ s. ``position`` is the location in world space of the mouse pointer on the surface of the shape with index ``shape_idx`` and ``normal`` is the normal vector of the surface at that point. Connect to the :ref:`input_event<class_CollisionObject_signal_input_event>` signal to easily pick up these events.
  135. ----
  136. .. _class_CollisionObject_method_create_shape_owner:
  137. - :ref:`int<class_int>` **create_shape_owner** **(** :ref:`Object<class_Object>` owner **)**
  138. Creates a new shape owner for the given object. Returns ``owner_id`` of the new owner for future reference.
  139. ----
  140. .. _class_CollisionObject_method_get_collision_layer_bit:
  141. - :ref:`bool<class_bool>` **get_collision_layer_bit** **(** :ref:`int<class_int>` bit **)** |const|
  142. Returns whether or not the specified ``bit`` of the :ref:`collision_layer<class_CollisionObject_property_collision_layer>` is set.
  143. ----
  144. .. _class_CollisionObject_method_get_collision_mask_bit:
  145. - :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** |const|
  146. Returns whether or not the specified ``bit`` of the :ref:`collision_mask<class_CollisionObject_property_collision_mask>` is set.
  147. ----
  148. .. _class_CollisionObject_method_get_rid:
  149. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  150. Returns the object's :ref:`RID<class_RID>`.
  151. ----
  152. .. _class_CollisionObject_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_CollisionObject_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_CollisionObject_method_remove_shape_owner:
  161. - void **remove_shape_owner** **(** :ref:`int<class_int>` owner_id **)**
  162. Removes the given shape owner.
  163. ----
  164. .. _class_CollisionObject_method_set_collision_layer_bit:
  165. - void **set_collision_layer_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  166. If ``value`` is ``true``, sets the specified ``bit`` in the the :ref:`collision_layer<class_CollisionObject_property_collision_layer>`.
  167. If ``value`` is ``false``, clears the specified ``bit`` in the the :ref:`collision_layer<class_CollisionObject_property_collision_layer>`.
  168. ----
  169. .. _class_CollisionObject_method_set_collision_mask_bit:
  170. - void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  171. If ``value`` is ``true``, sets the specified ``bit`` in the the :ref:`collision_mask<class_CollisionObject_property_collision_mask>`.
  172. If ``value`` is ``false``, clears the specified ``bit`` in the the :ref:`collision_mask<class_CollisionObject_property_collision_mask>`.
  173. ----
  174. .. _class_CollisionObject_method_shape_find_owner:
  175. - :ref:`int<class_int>` **shape_find_owner** **(** :ref:`int<class_int>` shape_index **)** |const|
  176. Returns the ``owner_id`` of the given shape.
  177. ----
  178. .. _class_CollisionObject_method_shape_owner_add_shape:
  179. - void **shape_owner_add_shape** **(** :ref:`int<class_int>` owner_id, :ref:`Shape<class_Shape>` shape **)**
  180. Adds a :ref:`Shape<class_Shape>` to the shape owner.
  181. ----
  182. .. _class_CollisionObject_method_shape_owner_clear_shapes:
  183. - void **shape_owner_clear_shapes** **(** :ref:`int<class_int>` owner_id **)**
  184. Removes all shapes from the shape owner.
  185. ----
  186. .. _class_CollisionObject_method_shape_owner_get_owner:
  187. - :ref:`Object<class_Object>` **shape_owner_get_owner** **(** :ref:`int<class_int>` owner_id **)** |const|
  188. Returns the parent object of the given shape owner.
  189. ----
  190. .. _class_CollisionObject_method_shape_owner_get_shape:
  191. - :ref:`Shape<class_Shape>` **shape_owner_get_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  192. Returns the :ref:`Shape<class_Shape>` with the given id from the given shape owner.
  193. ----
  194. .. _class_CollisionObject_method_shape_owner_get_shape_count:
  195. - :ref:`int<class_int>` **shape_owner_get_shape_count** **(** :ref:`int<class_int>` owner_id **)** |const|
  196. Returns the number of shapes the given shape owner contains.
  197. ----
  198. .. _class_CollisionObject_method_shape_owner_get_shape_index:
  199. - :ref:`int<class_int>` **shape_owner_get_shape_index** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  200. Returns the child index of the :ref:`Shape<class_Shape>` with the given id from the given shape owner.
  201. ----
  202. .. _class_CollisionObject_method_shape_owner_get_transform:
  203. - :ref:`Transform<class_Transform>` **shape_owner_get_transform** **(** :ref:`int<class_int>` owner_id **)** |const|
  204. Returns the shape owner's :ref:`Transform<class_Transform>`.
  205. ----
  206. .. _class_CollisionObject_method_shape_owner_remove_shape:
  207. - void **shape_owner_remove_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)**
  208. Removes a shape from the given shape owner.
  209. ----
  210. .. _class_CollisionObject_method_shape_owner_set_disabled:
  211. - void **shape_owner_set_disabled** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)**
  212. If ``true``, disables the given shape owner.
  213. ----
  214. .. _class_CollisionObject_method_shape_owner_set_transform:
  215. - void **shape_owner_set_transform** **(** :ref:`int<class_int>` owner_id, :ref:`Transform<class_Transform>` transform **)**
  216. Sets the :ref:`Transform<class_Transform>` of the given shape owner.
  217. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  218. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  219. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`