class_raycast2d.rst 13 KB

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