class_collisionobject.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/CollisionObject.xml.
  6. .. _class_CollisionObject:
  7. CollisionObject
  8. ===============
  9. **Inherits:** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`Area<class_Area>`, :ref:`PhysicsBody<class_PhysicsBody>`
  11. Base node for collision objects.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. 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.
  16. \ **Warning:** With a non-uniform scale this node will probably not function as expected. Please make sure to keep its scale uniform (i.e. the same on all axes), and change the size(s) of its collision shape(s) instead.
  17. .. rst-class:: classref-reftable-group
  18. Properties
  19. ----------
  20. .. table::
  21. :widths: auto
  22. +-------------------------+------------------------------------------------------------------------------------+-----------+
  23. | :ref:`int<class_int>` | :ref:`collision_layer<class_CollisionObject_property_collision_layer>` | ``1`` |
  24. +-------------------------+------------------------------------------------------------------------------------+-----------+
  25. | :ref:`int<class_int>` | :ref:`collision_mask<class_CollisionObject_property_collision_mask>` | ``1`` |
  26. +-------------------------+------------------------------------------------------------------------------------+-----------+
  27. | :ref:`bool<class_bool>` | :ref:`input_capture_on_drag<class_CollisionObject_property_input_capture_on_drag>` | ``false`` |
  28. +-------------------------+------------------------------------------------------------------------------------+-----------+
  29. | :ref:`bool<class_bool>` | :ref:`input_ray_pickable<class_CollisionObject_property_input_ray_pickable>` | ``true`` |
  30. +-------------------------+------------------------------------------------------------------------------------+-----------+
  31. .. rst-class:: classref-reftable-group
  32. Methods
  33. -------
  34. .. table::
  35. :widths: auto
  36. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | 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| |
  38. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`create_shape_owner<class_CollisionObject_method_create_shape_owner>` **(** :ref:`Object<class_Object>` owner **)** |
  40. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_bit<class_CollisionObject_method_get_collision_layer_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  42. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_CollisionObject_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  44. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`RID<class_RID>` | :ref:`get_rid<class_CollisionObject_method_get_rid>` **(** **)** |const| |
  46. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Array<class_Array>` | :ref:`get_shape_owners<class_CollisionObject_method_get_shape_owners>` **(** **)** |
  48. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_disabled<class_CollisionObject_method_is_shape_owner_disabled>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  50. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`remove_shape_owner<class_CollisionObject_method_remove_shape_owner>` **(** :ref:`int<class_int>` owner_id **)** |
  52. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_collision_layer_bit<class_CollisionObject_method_set_collision_layer_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  54. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_collision_mask_bit<class_CollisionObject_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  56. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`shape_find_owner<class_CollisionObject_method_shape_find_owner>` **(** :ref:`int<class_int>` shape_index **)** |const| |
  58. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`shape_owner_add_shape<class_CollisionObject_method_shape_owner_add_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`Shape<class_Shape>` shape **)** |
  60. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`shape_owner_clear_shapes<class_CollisionObject_method_shape_owner_clear_shapes>` **(** :ref:`int<class_int>` owner_id **)** |
  62. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Object<class_Object>` | :ref:`shape_owner_get_owner<class_CollisionObject_method_shape_owner_get_owner>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  64. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :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| |
  66. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :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| |
  68. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :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| |
  70. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Transform<class_Transform>` | :ref:`shape_owner_get_transform<class_CollisionObject_method_shape_owner_get_transform>` **(** :ref:`int<class_int>` owner_id **)** |const| |
  72. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | 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 **)** |
  74. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`shape_owner_set_disabled<class_CollisionObject_method_shape_owner_set_disabled>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)** |
  76. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`shape_owner_set_transform<class_CollisionObject_method_shape_owner_set_transform>` **(** :ref:`int<class_int>` owner_id, :ref:`Transform<class_Transform>` transform **)** |
  78. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Signals
  83. -------
  84. .. _class_CollisionObject_signal_input_event:
  85. .. rst-class:: classref-signal
  86. **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 **)**
  87. 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.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_CollisionObject_signal_mouse_entered:
  91. .. rst-class:: classref-signal
  92. **mouse_entered** **(** **)**
  93. Emitted when the mouse pointer enters any of this object's shapes.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_CollisionObject_signal_mouse_exited:
  97. .. rst-class:: classref-signal
  98. **mouse_exited** **(** **)**
  99. Emitted when the mouse pointer exits all this object's shapes.
  100. .. rst-class:: classref-section-separator
  101. ----
  102. .. rst-class:: classref-descriptions-group
  103. Property Descriptions
  104. ---------------------
  105. .. _class_CollisionObject_property_collision_layer:
  106. .. rst-class:: classref-property
  107. :ref:`int<class_int>` **collision_layer** = ``1``
  108. .. rst-class:: classref-property-setget
  109. - void **set_collision_layer** **(** :ref:`int<class_int>` value **)**
  110. - :ref:`int<class_int>` **get_collision_layer** **(** **)**
  111. 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>`.
  112. \ **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 <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_CollisionObject_property_collision_mask:
  116. .. rst-class:: classref-property
  117. :ref:`int<class_int>` **collision_mask** = ``1``
  118. .. rst-class:: classref-property-setget
  119. - void **set_collision_mask** **(** :ref:`int<class_int>` value **)**
  120. - :ref:`int<class_int>` **get_collision_mask** **(** **)**
  121. 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>`.
  122. \ **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 <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_CollisionObject_property_input_capture_on_drag:
  126. .. rst-class:: classref-property
  127. :ref:`bool<class_bool>` **input_capture_on_drag** = ``false``
  128. .. rst-class:: classref-property-setget
  129. - void **set_capture_input_on_drag** **(** :ref:`bool<class_bool>` value **)**
  130. - :ref:`bool<class_bool>` **get_capture_input_on_drag** **(** **)**
  131. If ``true``, the **CollisionObject** will continue to receive input events as the mouse is dragged across its shapes.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_CollisionObject_property_input_ray_pickable:
  135. .. rst-class:: classref-property
  136. :ref:`bool<class_bool>` **input_ray_pickable** = ``true``
  137. .. rst-class:: classref-property-setget
  138. - void **set_ray_pickable** **(** :ref:`bool<class_bool>` value **)**
  139. - :ref:`bool<class_bool>` **is_ray_pickable** **(** **)**
  140. 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.
  141. .. rst-class:: classref-section-separator
  142. ----
  143. .. rst-class:: classref-descriptions-group
  144. Method Descriptions
  145. -------------------
  146. .. _class_CollisionObject_method__input_event:
  147. .. rst-class:: classref-method
  148. 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|
  149. 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.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_CollisionObject_method_create_shape_owner:
  153. .. rst-class:: classref-method
  154. :ref:`int<class_int>` **create_shape_owner** **(** :ref:`Object<class_Object>` owner **)**
  155. Creates a new shape owner for the given object. Returns ``owner_id`` of the new owner for future reference.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_CollisionObject_method_get_collision_layer_bit:
  159. .. rst-class:: classref-method
  160. :ref:`bool<class_bool>` **get_collision_layer_bit** **(** :ref:`int<class_int>` bit **)** |const|
  161. Returns whether or not the specified ``bit`` of the :ref:`collision_layer<class_CollisionObject_property_collision_layer>` is set.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_CollisionObject_method_get_collision_mask_bit:
  165. .. rst-class:: classref-method
  166. :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** |const|
  167. Returns whether or not the specified ``bit`` of the :ref:`collision_mask<class_CollisionObject_property_collision_mask>` is set.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_CollisionObject_method_get_rid:
  171. .. rst-class:: classref-method
  172. :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  173. Returns the object's :ref:`RID<class_RID>`.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_CollisionObject_method_get_shape_owners:
  177. .. rst-class:: classref-method
  178. :ref:`Array<class_Array>` **get_shape_owners** **(** **)**
  179. 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.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_CollisionObject_method_is_shape_owner_disabled:
  183. .. rst-class:: classref-method
  184. :ref:`bool<class_bool>` **is_shape_owner_disabled** **(** :ref:`int<class_int>` owner_id **)** |const|
  185. If ``true``, the shape owner and its shapes are disabled.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_CollisionObject_method_remove_shape_owner:
  189. .. rst-class:: classref-method
  190. void **remove_shape_owner** **(** :ref:`int<class_int>` owner_id **)**
  191. Removes the given shape owner.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_CollisionObject_method_set_collision_layer_bit:
  195. .. rst-class:: classref-method
  196. void **set_collision_layer_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  197. If ``value`` is ``true``, sets the specified ``bit`` in the :ref:`collision_layer<class_CollisionObject_property_collision_layer>`.
  198. If ``value`` is ``false``, clears the specified ``bit`` in the :ref:`collision_layer<class_CollisionObject_property_collision_layer>`.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_CollisionObject_method_set_collision_mask_bit:
  202. .. rst-class:: classref-method
  203. void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  204. If ``value`` is ``true``, sets the specified ``bit`` in the :ref:`collision_mask<class_CollisionObject_property_collision_mask>`.
  205. If ``value`` is ``false``, clears the specified ``bit`` in the :ref:`collision_mask<class_CollisionObject_property_collision_mask>`.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_CollisionObject_method_shape_find_owner:
  209. .. rst-class:: classref-method
  210. :ref:`int<class_int>` **shape_find_owner** **(** :ref:`int<class_int>` shape_index **)** |const|
  211. Returns the ``owner_id`` of the given shape.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_CollisionObject_method_shape_owner_add_shape:
  215. .. rst-class:: classref-method
  216. void **shape_owner_add_shape** **(** :ref:`int<class_int>` owner_id, :ref:`Shape<class_Shape>` shape **)**
  217. Adds a :ref:`Shape<class_Shape>` to the shape owner.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_CollisionObject_method_shape_owner_clear_shapes:
  221. .. rst-class:: classref-method
  222. void **shape_owner_clear_shapes** **(** :ref:`int<class_int>` owner_id **)**
  223. Removes all shapes from the shape owner.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_CollisionObject_method_shape_owner_get_owner:
  227. .. rst-class:: classref-method
  228. :ref:`Object<class_Object>` **shape_owner_get_owner** **(** :ref:`int<class_int>` owner_id **)** |const|
  229. Returns the parent object of the given shape owner.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_CollisionObject_method_shape_owner_get_shape:
  233. .. rst-class:: classref-method
  234. :ref:`Shape<class_Shape>` **shape_owner_get_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  235. Returns the :ref:`Shape<class_Shape>` with the given id from the given shape owner.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_CollisionObject_method_shape_owner_get_shape_count:
  239. .. rst-class:: classref-method
  240. :ref:`int<class_int>` **shape_owner_get_shape_count** **(** :ref:`int<class_int>` owner_id **)** |const|
  241. Returns the number of shapes the given shape owner contains.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_CollisionObject_method_shape_owner_get_shape_index:
  245. .. rst-class:: classref-method
  246. :ref:`int<class_int>` **shape_owner_get_shape_index** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |const|
  247. Returns the child index of the :ref:`Shape<class_Shape>` with the given id from the given shape owner.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_CollisionObject_method_shape_owner_get_transform:
  251. .. rst-class:: classref-method
  252. :ref:`Transform<class_Transform>` **shape_owner_get_transform** **(** :ref:`int<class_int>` owner_id **)** |const|
  253. Returns the shape owner's :ref:`Transform<class_Transform>`.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_CollisionObject_method_shape_owner_remove_shape:
  257. .. rst-class:: classref-method
  258. void **shape_owner_remove_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)**
  259. Removes a shape from the given shape owner.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_CollisionObject_method_shape_owner_set_disabled:
  263. .. rst-class:: classref-method
  264. void **shape_owner_set_disabled** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)**
  265. If ``true``, disables the given shape owner.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_CollisionObject_method_shape_owner_set_transform:
  269. .. rst-class:: classref-method
  270. void **shape_owner_set_transform** **(** :ref:`int<class_int>` owner_id, :ref:`Transform<class_Transform>` transform **)**
  271. Sets the :ref:`Transform<class_Transform>` of the given shape owner.
  272. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  273. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  274. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  275. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`