RayCast2D.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="RayCast2D" inherits="Node2D" category="Core" version="3.0.alpha.custom_build">
  3. <brief_description>
  4. Query the closest object intersecting a ray.
  5. </brief_description>
  6. <description>
  7. A RayCast represents a line from its origin to its destination position, [code]cast_to[/code]. It is used to query the 2D space in order to find the closest object along the path of the ray.
  8. RayCast2D can ignore some objects by adding them to the exception list via [code]add_exception[/code], by setting proper filtering with collision layers, or by filtering object types with type masks.
  9. Only enabled raycasts will be able to query the space and report collisions.
  10. RayCast2D calculates intersection every physics frame (see [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 [method force_raycast_update] after adjusting the raycast.
  11. </description>
  12. <tutorials>
  13. </tutorials>
  14. <demos>
  15. </demos>
  16. <methods>
  17. <method name="add_exception">
  18. <return type="void">
  19. </return>
  20. <argument index="0" name="node" type="Object">
  21. </argument>
  22. <description>
  23. Adds a collision exception so the ray does not report collisions with the specified node.
  24. </description>
  25. </method>
  26. <method name="add_exception_rid">
  27. <return type="void">
  28. </return>
  29. <argument index="0" name="rid" type="RID">
  30. </argument>
  31. <description>
  32. Adds a collision exception so the ray does not report collisions with the specified [RID].
  33. </description>
  34. </method>
  35. <method name="clear_exceptions">
  36. <return type="void">
  37. </return>
  38. <description>
  39. Removes all collision exceptions for this ray.
  40. </description>
  41. </method>
  42. <method name="force_raycast_update">
  43. <return type="void">
  44. </return>
  45. <description>
  46. Updates the collision information for the ray. Use this method to update the collision information immediately instead of waiting for the next [code]_physics_process[/code] call, for example if the ray or its parent has changed state. Note: [code]enabled == true[/code] is not required for this to work.
  47. </description>
  48. </method>
  49. <method name="get_cast_to" qualifiers="const">
  50. <return type="Vector2">
  51. </return>
  52. <description>
  53. Return the destination point of this ray object.
  54. </description>
  55. </method>
  56. <method name="get_collider" qualifiers="const">
  57. <return type="Object">
  58. </return>
  59. <description>
  60. Returns the closest object the ray is pointing to. Note that this does not consider the length of the ray, so you must also use [method is_colliding] to check if the object returned is actually colliding with the ray.
  61. Example:
  62. [codeblock]
  63. if RayCast2D.is_colliding():
  64. var collider = RayCast2D.get_collider()
  65. [/codeblock]
  66. </description>
  67. </method>
  68. <method name="get_collider_shape" qualifiers="const">
  69. <return type="int">
  70. </return>
  71. <description>
  72. Returns the collision shape of the closest object the ray is pointing to. Note that this does not consider the length of the ray, so you must also use [method is_colliding] to check if the object returned is actually colliding with the ray.
  73. Example:
  74. [codeblock]
  75. if RayCast2D.is_colliding():
  76. var shape = RayCast2D.get_collider_shape()
  77. [/codeblock]
  78. </description>
  79. </method>
  80. <method name="get_collision_mask" qualifiers="const">
  81. <return type="int">
  82. </return>
  83. <description>
  84. Returns the collision mask for this ray.
  85. </description>
  86. </method>
  87. <method name="get_collision_mask_bit" qualifiers="const">
  88. <return type="bool">
  89. </return>
  90. <argument index="0" name="bit" type="int">
  91. </argument>
  92. <description>
  93. </description>
  94. </method>
  95. <method name="get_collision_normal" qualifiers="const">
  96. <return type="Vector2">
  97. </return>
  98. <description>
  99. Returns the normal of the intersecting object's shape at the collision point.
  100. </description>
  101. </method>
  102. <method name="get_collision_point" qualifiers="const">
  103. <return type="Vector2">
  104. </return>
  105. <description>
  106. Returns the collision point at which the ray intersects the closest object. Note: this point is in the [b]global[/b] coordinate system.
  107. </description>
  108. </method>
  109. <method name="get_exclude_parent_body" qualifiers="const">
  110. <return type="bool">
  111. </return>
  112. <description>
  113. Returns whether this ray should hit your parent node, if it's a body.
  114. </description>
  115. </method>
  116. <method name="get_type_mask" qualifiers="const">
  117. <return type="int">
  118. </return>
  119. <description>
  120. Returns the type mask (types of objects to detect) for this ray. The value is a sum (bitwise OR'd) of constants available for [Physics2DDirectSpaceState].
  121. </description>
  122. </method>
  123. <method name="is_colliding" qualifiers="const">
  124. <return type="bool">
  125. </return>
  126. <description>
  127. Return whether the closest object the ray is pointing to is colliding with the vector (considering the vector length).
  128. </description>
  129. </method>
  130. <method name="is_enabled" qualifiers="const">
  131. <return type="bool">
  132. </return>
  133. <description>
  134. Returns whether this raycast is enabled or not.
  135. </description>
  136. </method>
  137. <method name="remove_exception">
  138. <return type="void">
  139. </return>
  140. <argument index="0" name="node" type="Object">
  141. </argument>
  142. <description>
  143. Removes a collision exception so the ray does report collisions with the specified node.
  144. </description>
  145. </method>
  146. <method name="remove_exception_rid">
  147. <return type="void">
  148. </return>
  149. <argument index="0" name="rid" type="RID">
  150. </argument>
  151. <description>
  152. Removes a collision exception so the ray does report collisions with the specified [RID].
  153. </description>
  154. </method>
  155. <method name="set_cast_to">
  156. <return type="void">
  157. </return>
  158. <argument index="0" name="local_point" type="Vector2">
  159. </argument>
  160. <description>
  161. Sets the ray destination point, so that the ray will test from the ray's origin to [code]local_point[/code]
  162. </description>
  163. </method>
  164. <method name="set_collision_mask">
  165. <return type="void">
  166. </return>
  167. <argument index="0" name="mask" type="int">
  168. </argument>
  169. <description>
  170. Set the mask to filter objects. Only objects in at least one collision layer enabled in the mask will be detected.
  171. </description>
  172. </method>
  173. <method name="set_collision_mask_bit">
  174. <return type="void">
  175. </return>
  176. <argument index="0" name="bit" type="int">
  177. </argument>
  178. <argument index="1" name="value" type="bool">
  179. </argument>
  180. <description>
  181. </description>
  182. </method>
  183. <method name="set_enabled">
  184. <return type="void">
  185. </return>
  186. <argument index="0" name="enabled" type="bool">
  187. </argument>
  188. <description>
  189. Enables the RayCast2D. Only enabled raycasts will be able to query the space and report collisions.
  190. </description>
  191. </method>
  192. <method name="set_exclude_parent_body">
  193. <return type="void">
  194. </return>
  195. <argument index="0" name="mask" type="bool">
  196. </argument>
  197. <description>
  198. Toggle whether this ray should hit your parent node, if it's a body.
  199. </description>
  200. </method>
  201. <method name="set_type_mask">
  202. <return type="void">
  203. </return>
  204. <argument index="0" name="mask" type="int">
  205. </argument>
  206. <description>
  207. Set the types of objects to detect. For [code]mask[/code] use a logic sum (OR operation) of constants defined in [Physics2DDirectSpaceState], eg. [code]Physics2DDirectSpaceState.TYPE_MASK_STATIC_BODY | Physics2DDirectSpaceState.TYPE_MASK_KINEMATIC_BODY[/code] to detect only those two types.
  208. </description>
  209. </method>
  210. </methods>
  211. <members>
  212. <member name="cast_to" type="Vector2" setter="set_cast_to" getter="get_cast_to">
  213. The ray's destination point, relative to the RayCast's [code]position[/code].
  214. </member>
  215. <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask">
  216. The ray's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
  217. </member>
  218. <member name="enabled" type="bool" setter="set_enabled" getter="is_enabled">
  219. If [code]true[/code], collisions will be reported. Default value: [code]false[/code].
  220. </member>
  221. <member name="exclude_parent" type="bool" setter="set_exclude_parent_body" getter="get_exclude_parent_body">
  222. If [code]true[/code], the parent node will be excluded from collision detection. Default value: [code]true[/code].
  223. </member>
  224. <member name="type_mask" type="int" setter="set_type_mask" getter="get_type_mask">
  225. Object types to detect using a logical sum (OR operation) of type constants defined in [Physics2DDirectSpaceState].
  226. Example:
  227. [codeblock]
  228. RayCast.type_mask = Physics2DDirectSpaceState.TYPE_MASK_STATIC_BODY | Physics2DDirectSpaceState.TYPE_MASK_KINEMATIC_BODY
  229. [/codeblock]
  230. </member>
  231. </members>
  232. <constants>
  233. </constants>
  234. </class>