class_raycast3d.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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/4.1/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/RayCast3D.xml.
  6. .. _class_RayCast3D:
  7. RayCast3D
  8. =========
  9. **Inherits:** :ref:`Node3D<class_Node3D>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. A ray in 3D space, used to find the first :ref:`CollisionObject3D<class_CollisionObject3D>` it intersects.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. A raycast represents a ray from its origin to its :ref:`target_position<class_RayCast3D_property_target_position>` that finds the closest :ref:`CollisionObject3D<class_CollisionObject3D>` along its path, if it intersects any. This is useful for a lot of things, such as
  15. \ **RayCast3D** can ignore some objects by adding them to an exception list, by making its detection reporting ignore :ref:`Area3D<class_Area3D>`\ s (:ref:`collide_with_areas<class_RayCast3D_property_collide_with_areas>`) or :ref:`PhysicsBody3D<class_PhysicsBody3D>`\ s (:ref:`collide_with_bodies<class_RayCast3D_property_collide_with_bodies>`), or by configuring physics layers.
  16. \ **RayCast3D** calculates intersection every physics frame, and it holds the result until the next physics frame. For an immediate raycast, or if you want to configure a **RayCast3D** multiple times within the same physics frame, use :ref:`force_raycast_update<class_RayCast3D_method_force_raycast_update>`.
  17. To sweep over a region of 3D space, you can approximate the region with multiple **RayCast3D**\ s or use :ref:`ShapeCast3D<class_ShapeCast3D>`.
  18. .. rst-class:: classref-introduction-group
  19. Tutorials
  20. ---------
  21. - :doc:`Ray-casting <../tutorials/physics/ray-casting>`
  22. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  29. | :ref:`bool<class_bool>` | :ref:`collide_with_areas<class_RayCast3D_property_collide_with_areas>` | ``false`` |
  30. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  31. | :ref:`bool<class_bool>` | :ref:`collide_with_bodies<class_RayCast3D_property_collide_with_bodies>` | ``true`` |
  32. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  33. | :ref:`int<class_int>` | :ref:`collision_mask<class_RayCast3D_property_collision_mask>` | ``1`` |
  34. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  35. | :ref:`Color<class_Color>` | :ref:`debug_shape_custom_color<class_RayCast3D_property_debug_shape_custom_color>` | ``Color(0, 0, 0, 1)`` |
  36. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  37. | :ref:`int<class_int>` | :ref:`debug_shape_thickness<class_RayCast3D_property_debug_shape_thickness>` | ``2`` |
  38. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  39. | :ref:`bool<class_bool>` | :ref:`enabled<class_RayCast3D_property_enabled>` | ``true`` |
  40. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  41. | :ref:`bool<class_bool>` | :ref:`exclude_parent<class_RayCast3D_property_exclude_parent>` | ``true`` |
  42. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  43. | :ref:`bool<class_bool>` | :ref:`hit_from_inside<class_RayCast3D_property_hit_from_inside>` | ``false`` |
  44. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  45. | :ref:`Vector3<class_Vector3>` | :ref:`target_position<class_RayCast3D_property_target_position>` | ``Vector3(0, -1, 0)`` |
  46. +-------------------------------+------------------------------------------------------------------------------------+-----------------------+
  47. .. rst-class:: classref-reftable-group
  48. Methods
  49. -------
  50. .. table::
  51. :widths: auto
  52. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`add_exception<class_RayCast3D_method_add_exception>` **(** :ref:`CollisionObject3D<class_CollisionObject3D>` node **)** |
  54. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`add_exception_rid<class_RayCast3D_method_add_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  56. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`clear_exceptions<class_RayCast3D_method_clear_exceptions>` **(** **)** |
  58. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`force_raycast_update<class_RayCast3D_method_force_raycast_update>` **(** **)** |
  60. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Object<class_Object>` | :ref:`get_collider<class_RayCast3D_method_get_collider>` **(** **)** |const| |
  62. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`RID<class_RID>` | :ref:`get_collider_rid<class_RayCast3D_method_get_collider_rid>` **(** **)** |const| |
  64. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`int<class_int>` | :ref:`get_collider_shape<class_RayCast3D_method_get_collider_shape>` **(** **)** |const| |
  66. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_value<class_RayCast3D_method_get_collision_mask_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  68. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Vector3<class_Vector3>` | :ref:`get_collision_normal<class_RayCast3D_method_get_collision_normal>` **(** **)** |const| |
  70. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Vector3<class_Vector3>` | :ref:`get_collision_point<class_RayCast3D_method_get_collision_point>` **(** **)** |const| |
  72. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`is_colliding<class_RayCast3D_method_is_colliding>` **(** **)** |const| |
  74. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`remove_exception<class_RayCast3D_method_remove_exception>` **(** :ref:`CollisionObject3D<class_CollisionObject3D>` node **)** |
  76. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`remove_exception_rid<class_RayCast3D_method_remove_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  78. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`set_collision_mask_value<class_RayCast3D_method_set_collision_mask_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  80. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. .. rst-class:: classref-section-separator
  82. ----
  83. .. rst-class:: classref-descriptions-group
  84. Property Descriptions
  85. ---------------------
  86. .. _class_RayCast3D_property_collide_with_areas:
  87. .. rst-class:: classref-property
  88. :ref:`bool<class_bool>` **collide_with_areas** = ``false``
  89. .. rst-class:: classref-property-setget
  90. - void **set_collide_with_areas** **(** :ref:`bool<class_bool>` value **)**
  91. - :ref:`bool<class_bool>` **is_collide_with_areas_enabled** **(** **)**
  92. If ``true``, collision with :ref:`Area3D<class_Area3D>`\ s will be reported.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_RayCast3D_property_collide_with_bodies:
  96. .. rst-class:: classref-property
  97. :ref:`bool<class_bool>` **collide_with_bodies** = ``true``
  98. .. rst-class:: classref-property-setget
  99. - void **set_collide_with_bodies** **(** :ref:`bool<class_bool>` value **)**
  100. - :ref:`bool<class_bool>` **is_collide_with_bodies_enabled** **(** **)**
  101. If ``true``, collision with :ref:`PhysicsBody3D<class_PhysicsBody3D>`\ s will be reported.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_RayCast3D_property_collision_mask:
  105. .. rst-class:: classref-property
  106. :ref:`int<class_int>` **collision_mask** = ``1``
  107. .. rst-class:: classref-property-setget
  108. - void **set_collision_mask** **(** :ref:`int<class_int>` value **)**
  109. - :ref:`int<class_int>` **get_collision_mask** **(** **)**
  110. The ray's collision mask. Only objects in at least one collision layer enabled in the mask will be detected. See `Collision layers and masks <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_RayCast3D_property_debug_shape_custom_color:
  114. .. rst-class:: classref-property
  115. :ref:`Color<class_Color>` **debug_shape_custom_color** = ``Color(0, 0, 0, 1)``
  116. .. rst-class:: classref-property-setget
  117. - void **set_debug_shape_custom_color** **(** :ref:`Color<class_Color>` value **)**
  118. - :ref:`Color<class_Color>` **get_debug_shape_custom_color** **(** **)**
  119. The custom color to use to draw the shape in the editor and at run-time if **Visible Collision Shapes** is enabled in the **Debug** menu. This color will be highlighted at run-time if the **RayCast3D** is colliding with something.
  120. If set to ``Color(0.0, 0.0, 0.0)`` (by default), the color set in :ref:`ProjectSettings.debug/shapes/collision/shape_color<class_ProjectSettings_property_debug/shapes/collision/shape_color>` is used.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_RayCast3D_property_debug_shape_thickness:
  124. .. rst-class:: classref-property
  125. :ref:`int<class_int>` **debug_shape_thickness** = ``2``
  126. .. rst-class:: classref-property-setget
  127. - void **set_debug_shape_thickness** **(** :ref:`int<class_int>` value **)**
  128. - :ref:`int<class_int>` **get_debug_shape_thickness** **(** **)**
  129. If set to ``1``, a line is used as the debug shape. Otherwise, a truncated pyramid is drawn to represent the **RayCast3D**. Requires **Visible Collision Shapes** to be enabled in the **Debug** menu for the debug shape to be visible at run-time.
  130. .. rst-class:: classref-item-separator
  131. ----
  132. .. _class_RayCast3D_property_enabled:
  133. .. rst-class:: classref-property
  134. :ref:`bool<class_bool>` **enabled** = ``true``
  135. .. rst-class:: classref-property-setget
  136. - void **set_enabled** **(** :ref:`bool<class_bool>` value **)**
  137. - :ref:`bool<class_bool>` **is_enabled** **(** **)**
  138. If ``true``, collisions will be reported.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_RayCast3D_property_exclude_parent:
  142. .. rst-class:: classref-property
  143. :ref:`bool<class_bool>` **exclude_parent** = ``true``
  144. .. rst-class:: classref-property-setget
  145. - void **set_exclude_parent_body** **(** :ref:`bool<class_bool>` value **)**
  146. - :ref:`bool<class_bool>` **get_exclude_parent_body** **(** **)**
  147. If ``true``, collisions will be ignored for this RayCast3D's immediate parent.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_RayCast3D_property_hit_from_inside:
  151. .. rst-class:: classref-property
  152. :ref:`bool<class_bool>` **hit_from_inside** = ``false``
  153. .. rst-class:: classref-property-setget
  154. - void **set_hit_from_inside** **(** :ref:`bool<class_bool>` value **)**
  155. - :ref:`bool<class_bool>` **is_hit_from_inside_enabled** **(** **)**
  156. If ``true``, the ray will detect a hit when starting inside shapes. In this case the collision normal will be ``Vector3(0, 0, 0)``. Does not affect shapes with no volume like concave polygon or heightmap.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_RayCast3D_property_target_position:
  160. .. rst-class:: classref-property
  161. :ref:`Vector3<class_Vector3>` **target_position** = ``Vector3(0, -1, 0)``
  162. .. rst-class:: classref-property-setget
  163. - void **set_target_position** **(** :ref:`Vector3<class_Vector3>` value **)**
  164. - :ref:`Vector3<class_Vector3>` **get_target_position** **(** **)**
  165. The ray's destination point, relative to the RayCast's ``position``.
  166. .. rst-class:: classref-section-separator
  167. ----
  168. .. rst-class:: classref-descriptions-group
  169. Method Descriptions
  170. -------------------
  171. .. _class_RayCast3D_method_add_exception:
  172. .. rst-class:: classref-method
  173. void **add_exception** **(** :ref:`CollisionObject3D<class_CollisionObject3D>` node **)**
  174. Adds a collision exception so the ray does not report collisions with the specified :ref:`CollisionObject3D<class_CollisionObject3D>` node.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_RayCast3D_method_add_exception_rid:
  178. .. rst-class:: classref-method
  179. void **add_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  180. Adds a collision exception so the ray does not report collisions with the specified :ref:`RID<class_RID>`.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_RayCast3D_method_clear_exceptions:
  184. .. rst-class:: classref-method
  185. void **clear_exceptions** **(** **)**
  186. Removes all collision exceptions for this ray.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_RayCast3D_method_force_raycast_update:
  190. .. rst-class:: classref-method
  191. void **force_raycast_update** **(** **)**
  192. Updates the collision information for the ray. Use this method to update the collision information immediately instead of waiting for the next ``_physics_process`` call, for example if the ray or its parent has changed state.
  193. \ **Note:** :ref:`enabled<class_RayCast3D_property_enabled>` does not need to be ``true`` for this to work.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_RayCast3D_method_get_collider:
  197. .. rst-class:: classref-method
  198. :ref:`Object<class_Object>` **get_collider** **(** **)** |const|
  199. Returns the first object that the ray intersects, or ``null`` if no object is intersecting the ray (i.e. :ref:`is_colliding<class_RayCast3D_method_is_colliding>` returns ``false``).
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_RayCast3D_method_get_collider_rid:
  203. .. rst-class:: classref-method
  204. :ref:`RID<class_RID>` **get_collider_rid** **(** **)** |const|
  205. Returns the :ref:`RID<class_RID>` of the first object that the ray intersects, or an empty :ref:`RID<class_RID>` if no object is intersecting the ray (i.e. :ref:`is_colliding<class_RayCast3D_method_is_colliding>` returns ``false``).
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_RayCast3D_method_get_collider_shape:
  209. .. rst-class:: classref-method
  210. :ref:`int<class_int>` **get_collider_shape** **(** **)** |const|
  211. Returns the shape ID of the first object that the ray intersects, or ``0`` if no object is intersecting the ray (i.e. :ref:`is_colliding<class_RayCast3D_method_is_colliding>` returns ``false``).
  212. To get the intersected shape node, for a :ref:`CollisionObject3D<class_CollisionObject3D>` target, use:
  213. .. tabs::
  214. .. code-tab:: gdscript
  215. var target = get_collider() # A CollisionObject3D.
  216. var shape_id = get_collider_shape() # The shape index in the collider.
  217. var owner_id = target.shape_find_owner(shape_id) # The owner ID in the collider.
  218. var shape = target.shape_owner_get_owner(owner_id)
  219. .. code-tab:: csharp
  220. var target = (CollisionObject3D)GetCollider(); // A CollisionObject3D.
  221. var shapeId = GetColliderShape(); // The shape index in the collider.
  222. var ownerId = target.ShapeFindOwner(shapeId); // The owner ID in the collider.
  223. var shape = target.ShapeOwnerGetOwner(ownerId);
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_RayCast3D_method_get_collision_mask_value:
  227. .. rst-class:: classref-method
  228. :ref:`bool<class_bool>` **get_collision_mask_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  229. Returns whether or not the specified layer of the :ref:`collision_mask<class_RayCast3D_property_collision_mask>` is enabled, given a ``layer_number`` between 1 and 32.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_RayCast3D_method_get_collision_normal:
  233. .. rst-class:: classref-method
  234. :ref:`Vector3<class_Vector3>` **get_collision_normal** **(** **)** |const|
  235. Returns the normal of the intersecting object's shape at the collision point, or ``Vector3(0, 0, 0)`` if the ray starts inside the shape and :ref:`hit_from_inside<class_RayCast3D_property_hit_from_inside>` is ``true``.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_RayCast3D_method_get_collision_point:
  239. .. rst-class:: classref-method
  240. :ref:`Vector3<class_Vector3>` **get_collision_point** **(** **)** |const|
  241. Returns the collision point at which the ray intersects the closest object. If :ref:`hit_from_inside<class_RayCast3D_property_hit_from_inside>` is ``true`` and the ray starts inside of a collision shape, this function will return the origin point of the ray.
  242. \ **Note:** This point is in the **global** coordinate system.
  243. .. rst-class:: classref-item-separator
  244. ----
  245. .. _class_RayCast3D_method_is_colliding:
  246. .. rst-class:: classref-method
  247. :ref:`bool<class_bool>` **is_colliding** **(** **)** |const|
  248. Returns whether any object is intersecting with the ray's vector (considering the vector length).
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_RayCast3D_method_remove_exception:
  252. .. rst-class:: classref-method
  253. void **remove_exception** **(** :ref:`CollisionObject3D<class_CollisionObject3D>` node **)**
  254. Removes a collision exception so the ray does report collisions with the specified :ref:`CollisionObject3D<class_CollisionObject3D>` node.
  255. .. rst-class:: classref-item-separator
  256. ----
  257. .. _class_RayCast3D_method_remove_exception_rid:
  258. .. rst-class:: classref-method
  259. void **remove_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  260. Removes a collision exception so the ray does report collisions with the specified :ref:`RID<class_RID>`.
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_RayCast3D_method_set_collision_mask_value:
  264. .. rst-class:: classref-method
  265. void **set_collision_mask_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  266. Based on ``value``, enables or disables the specified layer in the :ref:`collision_mask<class_RayCast3D_property_collision_mask>`, given a ``layer_number`` between 1 and 32.
  267. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  268. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  269. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  270. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  271. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  272. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  273. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`