ShapeCast2D.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="ShapeCast2D" inherits="Node2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. Node for physics collision sweep and immediate overlap queries. Similar to the [RayCast2D] node.
  5. </brief_description>
  6. <description>
  7. Shape casting allows to detect collision objects by sweeping the [member shape] along the cast direction determined by [member target_position] (useful for things like beam weapons).
  8. Immediate collision overlaps can be done with the [member target_position] set to [code]Vector2(0, 0)[/code] and by calling [method force_shapecast_update] within the same [b]physics_frame[/b]. This also helps to overcome some limitations of [Area2D] when used as a continuous detection area, often requiring waiting a couple of frames before collision information is available to [Area2D] nodes, and when using the signals creates unnecessary complexity.
  9. The node can detect multiple collision objects, but it's usually used to detect the first collision.
  10. [b]Note:[/b] Shape casting is more computationally expensive compared to ray casting.
  11. </description>
  12. <tutorials>
  13. </tutorials>
  14. <methods>
  15. <method name="add_exception">
  16. <return type="void" />
  17. <argument index="0" name="node" type="Object" />
  18. <description>
  19. Adds a collision exception so the shape does not report collisions with the specified [CollisionObject2D] node.
  20. </description>
  21. </method>
  22. <method name="add_exception_rid">
  23. <return type="void" />
  24. <argument index="0" name="rid" type="RID" />
  25. <description>
  26. Adds a collision exception so the shape does not report collisions with the specified [RID].
  27. </description>
  28. </method>
  29. <method name="clear_exceptions">
  30. <return type="void" />
  31. <description>
  32. Removes all collision exceptions for this shape.
  33. </description>
  34. </method>
  35. <method name="force_shapecast_update">
  36. <return type="void" />
  37. <description>
  38. Updates the collision information for the shape. Use this method to update the collision information immediately instead of waiting for the next [code]_physics_process[/code] call, for example if the shape or its parent has changed state.
  39. [b]Note:[/b] [code]enabled[/code] is not required for this to work.
  40. </description>
  41. </method>
  42. <method name="get_closest_collision_safe_fraction" qualifiers="const">
  43. <return type="float" />
  44. <description>
  45. The fraction from the [ShapeCast2D]'s origin to its [member target_position] (between 0 and 1) of how far the shape can move without triggering a collision.
  46. </description>
  47. </method>
  48. <method name="get_closest_collision_unsafe_fraction" qualifiers="const">
  49. <return type="float" />
  50. <description>
  51. The fraction from the [ShapeCast2D]'s origin to its [member target_position] (between 0 and 1) of how far the shape must move to trigger a collision.
  52. </description>
  53. </method>
  54. <method name="get_collider" qualifiers="const">
  55. <return type="Object" />
  56. <argument index="0" name="index" type="int" />
  57. <description>
  58. Returns the collided [Object] of one of the multiple collisions at [code]index[/code], or [code]null[/code] if no object is intersecting the shape (i.e. [method is_colliding] returns [code]false[/code]).
  59. </description>
  60. </method>
  61. <method name="get_collider_rid" qualifiers="const">
  62. <return type="RID" />
  63. <argument index="0" name="index" type="int" />
  64. <description>
  65. Returns the [RID] of the collided object of one of the multiple collisions at [code]index[/code].
  66. </description>
  67. </method>
  68. <method name="get_collider_shape" qualifiers="const">
  69. <return type="int" />
  70. <argument index="0" name="index" type="int" />
  71. <description>
  72. Returns the shape ID of the colliding shape of one of the multiple collisions at [code]index[/code], or [code]0[/code] if no object is intersecting the shape (i.e. [method is_colliding] returns [code]false[/code]).
  73. </description>
  74. </method>
  75. <method name="get_collision_count" qualifiers="const">
  76. <return type="int" />
  77. <description>
  78. The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by [method get_collider], [method get_collider_shape], [method get_collision_point], and [method get_collision_normal] methods.
  79. </description>
  80. </method>
  81. <method name="get_collision_mask_value" qualifiers="const">
  82. <return type="bool" />
  83. <argument index="0" name="layer_number" type="int" />
  84. <description>
  85. Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [code]layer_number[/code] between 1 and 32.
  86. </description>
  87. </method>
  88. <method name="get_collision_normal" qualifiers="const">
  89. <return type="Vector2" />
  90. <argument index="0" name="index" type="int" />
  91. <description>
  92. Returns the normal of one of the multiple collisions at [code]index[/code] of the intersecting object.
  93. </description>
  94. </method>
  95. <method name="get_collision_point" qualifiers="const">
  96. <return type="Vector2" />
  97. <argument index="0" name="index" type="int" />
  98. <description>
  99. Returns the collision point of one of the multiple collisions at [code]index[/code] where the shape intersects the colliding object.
  100. [b]Note:[/b] this point is in the [b]global[/b] coordinate system.
  101. </description>
  102. </method>
  103. <method name="is_colliding" qualifiers="const">
  104. <return type="bool" />
  105. <description>
  106. Returns whether any object is intersecting with the shape's vector (considering the vector length).
  107. </description>
  108. </method>
  109. <method name="remove_exception">
  110. <return type="void" />
  111. <argument index="0" name="node" type="Object" />
  112. <description>
  113. Removes a collision exception so the shape does report collisions with the specified [CollisionObject2D] node.
  114. </description>
  115. </method>
  116. <method name="remove_exception_rid">
  117. <return type="void" />
  118. <argument index="0" name="rid" type="RID" />
  119. <description>
  120. Removes a collision exception so the shape does report collisions with the specified [RID].
  121. </description>
  122. </method>
  123. <method name="set_collision_mask_value">
  124. <return type="void" />
  125. <argument index="0" name="layer_number" type="int" />
  126. <argument index="1" name="value" type="bool" />
  127. <description>
  128. Based on [code]value[/code], enables or disables the specified layer in the [member collision_mask], given a [code]layer_number[/code] between 1 and 32.
  129. </description>
  130. </method>
  131. </methods>
  132. <members>
  133. <member name="collide_with_areas" type="bool" setter="set_collide_with_areas" getter="is_collide_with_areas_enabled" default="false">
  134. If [code]true[/code], collision with [Area2D]s will be reported.
  135. </member>
  136. <member name="collide_with_bodies" type="bool" setter="set_collide_with_bodies" getter="is_collide_with_bodies_enabled" default="true">
  137. If [code]true[/code], collision with [PhysicsBody2D]s will be reported.
  138. </member>
  139. <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
  140. The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
  141. </member>
  142. <member name="collision_result" type="Array" setter="" getter="_get_collision_result">
  143. Returns the complete collision information from the collision sweep. The data returned is the same as in the [method Physics2DDirectSpaceState.get_rest_info] method.
  144. </member>
  145. <member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">
  146. If [code]true[/code], collisions will be reported.
  147. </member>
  148. <member name="exclude_parent" type="bool" setter="set_exclude_parent_body" getter="get_exclude_parent_body" default="true">
  149. If [code]true[/code], the parent node will be excluded from collision detection.
  150. </member>
  151. <member name="margin" type="float" setter="set_margin" getter="get_margin" default="0.0">
  152. The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
  153. </member>
  154. <member name="max_results" type="int" setter="set_max_results" getter="get_max_results" default="32">
  155. The number of intersections can be limited with this parameter, to reduce the processing time.
  156. </member>
  157. <member name="shape" type="Shape2D" setter="set_shape" getter="get_shape">
  158. The [Shape2D]-derived shape to be used for collision queries.
  159. </member>
  160. <member name="target_position" type="Vector2" setter="set_target_position" getter="get_target_position" default="Vector2( 0, 50 )">
  161. The shape's destination point, relative to this node's [code]position[/code].
  162. </member>
  163. </members>
  164. <constants>
  165. </constants>
  166. </class>