class_raycast2d.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the RayCast2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_RayCast2D:
  6. RayCast2D
  7. =========
  8. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Query the closest object intersecting a ray.
  13. Properties
  14. ----------
  15. +-------------------------------+--------------------------------------------------------------------------+
  16. | :ref:`Vector2<class_Vector2>` | :ref:`cast_to<class_RayCast2D_property_cast_to>` |
  17. +-------------------------------+--------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`collide_with_areas<class_RayCast2D_property_collide_with_areas>` |
  19. +-------------------------------+--------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | :ref:`collide_with_bodies<class_RayCast2D_property_collide_with_bodies>` |
  21. +-------------------------------+--------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`collision_mask<class_RayCast2D_property_collision_mask>` |
  23. +-------------------------------+--------------------------------------------------------------------------+
  24. | :ref:`bool<class_bool>` | :ref:`enabled<class_RayCast2D_property_enabled>` |
  25. +-------------------------------+--------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`exclude_parent<class_RayCast2D_property_exclude_parent>` |
  27. +-------------------------------+--------------------------------------------------------------------------+
  28. Methods
  29. -------
  30. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`add_exception<class_RayCast2D_method_add_exception>` **(** :ref:`Object<class_Object>` node **)** |
  32. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`add_exception_rid<class_RayCast2D_method_add_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  34. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`clear_exceptions<class_RayCast2D_method_clear_exceptions>` **(** **)** |
  36. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`force_raycast_update<class_RayCast2D_method_force_raycast_update>` **(** **)** |
  38. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Object<class_Object>` | :ref:`get_collider<class_RayCast2D_method_get_collider>` **(** **)** const |
  40. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`get_collider_shape<class_RayCast2D_method_get_collider_shape>` **(** **)** const |
  42. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_RayCast2D_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** const |
  44. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_normal<class_RayCast2D_method_get_collision_normal>` **(** **)** const |
  46. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_point<class_RayCast2D_method_get_collision_point>` **(** **)** const |
  48. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_colliding<class_RayCast2D_method_is_colliding>` **(** **)** const |
  50. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`remove_exception<class_RayCast2D_method_remove_exception>` **(** :ref:`Object<class_Object>` node **)** |
  52. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`remove_exception_rid<class_RayCast2D_method_remove_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
  54. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_collision_mask_bit<class_RayCast2D_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  56. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  57. Description
  58. -----------
  59. A RayCast represents a line from its origin to its destination position, ``cast_to``. It is used to query the 2D space in order to find the closest object along the path of the ray.
  60. RayCast2D can ignore some objects by adding them to the exception list via ``add_exception``, by setting proper filtering with collision layers, or by filtering object types with type masks.
  61. RayCast2D can be configured to report collisions with :ref:`Area2D<class_Area2D>`\ s (:ref:`collide_with_areas<class_RayCast2D_property_collide_with_areas>`) and/or :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s (:ref:`collide_with_bodies<class_RayCast2D_property_collide_with_bodies>`).
  62. Only enabled raycasts will be able to query the space and report collisions.
  63. RayCast2D calculates intersection every physics frame (see :ref:`Node<class_Node>`), and the result is cached so it can be used later until the next frame. If multiple queries are required between physics frames (or during the same frame) use :ref:`force_raycast_update<class_RayCast2D_method_force_raycast_update>` after adjusting the raycast.
  64. Property Descriptions
  65. ---------------------
  66. .. _class_RayCast2D_property_cast_to:
  67. - :ref:`Vector2<class_Vector2>` **cast_to**
  68. +----------+--------------------+
  69. | *Setter* | set_cast_to(value) |
  70. +----------+--------------------+
  71. | *Getter* | get_cast_to() |
  72. +----------+--------------------+
  73. The ray's destination point, relative to the RayCast's ``position``.
  74. ----
  75. .. _class_RayCast2D_property_collide_with_areas:
  76. - :ref:`bool<class_bool>` **collide_with_areas**
  77. +----------+---------------------------------+
  78. | *Setter* | set_collide_with_areas(value) |
  79. +----------+---------------------------------+
  80. | *Getter* | is_collide_with_areas_enabled() |
  81. +----------+---------------------------------+
  82. If ``true``, collision with :ref:`Area2D<class_Area2D>`\ s will be reported. Default value: ``false``.
  83. ----
  84. .. _class_RayCast2D_property_collide_with_bodies:
  85. - :ref:`bool<class_bool>` **collide_with_bodies**
  86. +----------+----------------------------------+
  87. | *Setter* | set_collide_with_bodies(value) |
  88. +----------+----------------------------------+
  89. | *Getter* | is_collide_with_bodies_enabled() |
  90. +----------+----------------------------------+
  91. If ``true``, collision with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s will be reported. Default value: ``true``.
  92. ----
  93. .. _class_RayCast2D_property_collision_mask:
  94. - :ref:`int<class_int>` **collision_mask**
  95. +----------+---------------------------+
  96. | *Setter* | set_collision_mask(value) |
  97. +----------+---------------------------+
  98. | *Getter* | get_collision_mask() |
  99. +----------+---------------------------+
  100. The ray's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
  101. ----
  102. .. _class_RayCast2D_property_enabled:
  103. - :ref:`bool<class_bool>` **enabled**
  104. +----------+--------------------+
  105. | *Setter* | set_enabled(value) |
  106. +----------+--------------------+
  107. | *Getter* | is_enabled() |
  108. +----------+--------------------+
  109. If ``true``, collisions will be reported. Default value: ``false``.
  110. ----
  111. .. _class_RayCast2D_property_exclude_parent:
  112. - :ref:`bool<class_bool>` **exclude_parent**
  113. +----------+--------------------------------+
  114. | *Setter* | set_exclude_parent_body(value) |
  115. +----------+--------------------------------+
  116. | *Getter* | get_exclude_parent_body() |
  117. +----------+--------------------------------+
  118. If ``true``, the parent node will be excluded from collision detection. Default value: ``true``.
  119. Method Descriptions
  120. -------------------
  121. .. _class_RayCast2D_method_add_exception:
  122. - void **add_exception** **(** :ref:`Object<class_Object>` node **)**
  123. Adds a collision exception so the ray does not report collisions with the specified node.
  124. ----
  125. .. _class_RayCast2D_method_add_exception_rid:
  126. - void **add_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  127. Adds a collision exception so the ray does not report collisions with the specified :ref:`RID<class_RID>`.
  128. ----
  129. .. _class_RayCast2D_method_clear_exceptions:
  130. - void **clear_exceptions** **(** **)**
  131. Removes all collision exceptions for this ray.
  132. ----
  133. .. _class_RayCast2D_method_force_raycast_update:
  134. - void **force_raycast_update** **(** **)**
  135. 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. Note: ``enabled == true`` is not required for this to work.
  136. ----
  137. .. _class_RayCast2D_method_get_collider:
  138. - :ref:`Object<class_Object>` **get_collider** **(** **)** const
  139. Returns the first object that the ray intersects, or ``null`` if no object is intersecting the ray (i.e. :ref:`is_colliding<class_RayCast2D_method_is_colliding>` returns ``false``).
  140. ----
  141. .. _class_RayCast2D_method_get_collider_shape:
  142. - :ref:`int<class_int>` **get_collider_shape** **(** **)** const
  143. 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_RayCast2D_method_is_colliding>` returns ``false``).
  144. ----
  145. .. _class_RayCast2D_method_get_collision_mask_bit:
  146. - :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** const
  147. Returns an individual bit on the collision mask.
  148. ----
  149. .. _class_RayCast2D_method_get_collision_normal:
  150. - :ref:`Vector2<class_Vector2>` **get_collision_normal** **(** **)** const
  151. Returns the normal of the intersecting object's shape at the collision point.
  152. ----
  153. .. _class_RayCast2D_method_get_collision_point:
  154. - :ref:`Vector2<class_Vector2>` **get_collision_point** **(** **)** const
  155. Returns the collision point at which the ray intersects the closest object. Note: this point is in the **global** coordinate system.
  156. ----
  157. .. _class_RayCast2D_method_is_colliding:
  158. - :ref:`bool<class_bool>` **is_colliding** **(** **)** const
  159. Returns whether any object is intersecting with the ray's vector (considering the vector length).
  160. ----
  161. .. _class_RayCast2D_method_remove_exception:
  162. - void **remove_exception** **(** :ref:`Object<class_Object>` node **)**
  163. Removes a collision exception so the ray does report collisions with the specified node.
  164. ----
  165. .. _class_RayCast2D_method_remove_exception_rid:
  166. - void **remove_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
  167. Removes a collision exception so the ray does report collisions with the specified :ref:`RID<class_RID>`.
  168. ----
  169. .. _class_RayCast2D_method_set_collision_mask_bit:
  170. - void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  171. Set/clear individual bits on the collision mask. This makes selecting the areas scanned easier.