class_physics2ddirectspacestate.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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/3.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Physics2DDirectSpaceState.xml.
  6. .. _class_Physics2DDirectSpaceState:
  7. Physics2DDirectSpaceState
  8. =========================
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Direct access object to a space in the :ref:`Physics2DServer<class_Physics2DServer>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Direct access object to a space in the :ref:`Physics2DServer<class_Physics2DServer>`. It's used mainly to do queries against objects and areas residing in a given space.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  19. - :doc:`Ray-casting <../tutorials/physics/ray-casting>`
  20. .. rst-class:: classref-reftable-group
  21. Methods
  22. -------
  23. .. table::
  24. :widths: auto
  25. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Array<class_Array>` | :ref:`cast_motion<class_Physics2DDirectSpaceState_method_cast_motion>` **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape **)** |
  27. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Array<class_Array>` | :ref:`collide_shape<class_Physics2DDirectSpaceState_method_collide_shape>` **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape, :ref:`int<class_int>` max_results=32 **)** |
  29. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_rest_info<class_Physics2DDirectSpaceState_method_get_rest_info>` **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape **)** |
  31. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Array<class_Array>` | :ref:`intersect_point<class_Physics2DDirectSpaceState_method_intersect_point>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`int<class_int>` max_results=32, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)** |
  33. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Array<class_Array>` | :ref:`intersect_point_on_canvas<class_Physics2DDirectSpaceState_method_intersect_point_on_canvas>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`int<class_int>` canvas_instance_id, :ref:`int<class_int>` max_results=32, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)** |
  35. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Dictionary<class_Dictionary>` | :ref:`intersect_ray<class_Physics2DDirectSpaceState_method_intersect_ray>` **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)** |
  37. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Array<class_Array>` | :ref:`intersect_shape<class_Physics2DDirectSpaceState_method_intersect_shape>` **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape, :ref:`int<class_int>` max_results=32 **)** |
  39. +-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. .. rst-class:: classref-section-separator
  41. ----
  42. .. rst-class:: classref-descriptions-group
  43. Method Descriptions
  44. -------------------
  45. .. _class_Physics2DDirectSpaceState_method_cast_motion:
  46. .. rst-class:: classref-method
  47. :ref:`Array<class_Array>` **cast_motion** **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape **)**
  48. Checks how far a :ref:`Shape2D<class_Shape2D>` can move without colliding. All the parameters for the query, including the shape and the motion, are supplied through a :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` object.
  49. Returns an array with the safe and unsafe proportions (between 0 and 1) of the motion. The safe proportion is the maximum fraction of the motion that can be made without a collision. The unsafe proportion is the minimum fraction of the distance that must be moved for a collision. If no collision is detected a result of ``[1.0, 1.0]`` will be returned.
  50. \ **Note:** Any :ref:`Shape2D<class_Shape2D>`\ s that the shape is already colliding with e.g. inside of, will be ignored. Use :ref:`collide_shape<class_Physics2DDirectSpaceState_method_collide_shape>` to determine the :ref:`Shape2D<class_Shape2D>`\ s that the shape is already colliding with.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_Physics2DDirectSpaceState_method_collide_shape:
  54. .. rst-class:: classref-method
  55. :ref:`Array<class_Array>` **collide_shape** **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape, :ref:`int<class_int>` max_results=32 **)**
  56. Checks the intersections of a shape, given through a :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` object, against the space. The resulting array contains a list of points where the shape intersects another. Like with :ref:`intersect_shape<class_Physics2DDirectSpaceState_method_intersect_shape>`, the number of returned results can be limited to save processing time.
  57. .. rst-class:: classref-item-separator
  58. ----
  59. .. _class_Physics2DDirectSpaceState_method_get_rest_info:
  60. .. rst-class:: classref-method
  61. :ref:`Dictionary<class_Dictionary>` **get_rest_info** **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape **)**
  62. Checks the intersections of a shape, given through a :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` object, against the space. If it collides with more than one shape, the nearest one is selected. If the shape did not intersect anything, then an empty dictionary is returned instead.
  63. \ **Note:** This method does not take into account the ``motion`` property of the object. The returned object is a dictionary containing the following fields:
  64. \ ``collider_id``: The colliding object's ID.
  65. \ ``linear_velocity``: The colliding object's velocity :ref:`Vector2<class_Vector2>`. If the object is an :ref:`Area2D<class_Area2D>`, the result is ``(0, 0)``.
  66. \ ``metadata``: The intersecting shape's metadata. This metadata is different from :ref:`Object.get_meta<class_Object_method_get_meta>`, and is set with :ref:`Physics2DServer.shape_set_data<class_Physics2DServer_method_shape_set_data>`.
  67. \ ``normal``: The object's surface normal at the intersection point.
  68. \ ``point``: The intersection point.
  69. \ ``rid``: The intersecting object's :ref:`RID<class_RID>`.
  70. \ ``shape``: The shape index of the colliding shape.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_Physics2DDirectSpaceState_method_intersect_point:
  74. .. rst-class:: classref-method
  75. :ref:`Array<class_Array>` **intersect_point** **(** :ref:`Vector2<class_Vector2>` point, :ref:`int<class_int>` max_results=32, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)**
  76. Checks whether a point is inside any solid shape. The shapes the point is inside of are returned in an array containing dictionaries with the following fields:
  77. \ ``collider``: The colliding object.
  78. \ ``collider_id``: The colliding object's ID.
  79. \ ``metadata``: The intersecting shape's metadata. This metadata is different from :ref:`Object.get_meta<class_Object_method_get_meta>`, and is set with :ref:`Physics2DServer.shape_set_data<class_Physics2DServer_method_shape_set_data>`.
  80. \ ``rid``: The intersecting object's :ref:`RID<class_RID>`.
  81. \ ``shape``: The shape index of the colliding shape.
  82. The number of intersections can be limited with the ``max_results`` parameter, to reduce the processing time.
  83. Additionally, the method can take an ``exclude`` array of objects or :ref:`RID<class_RID>`\ s that are to be excluded from collisions, a ``collision_mask`` bitmask representing the physics layers to check in, or booleans to determine if the ray should collide with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s or :ref:`Area2D<class_Area2D>`\ s, respectively.
  84. \ **Note:** :ref:`ConcavePolygonShape2D<class_ConcavePolygonShape2D>`\ s and :ref:`CollisionPolygon2D<class_CollisionPolygon2D>`\ s in ``Segments`` build mode are not solid shapes. Therefore, they will not be detected.
  85. .. rst-class:: classref-item-separator
  86. ----
  87. .. _class_Physics2DDirectSpaceState_method_intersect_point_on_canvas:
  88. .. rst-class:: classref-method
  89. :ref:`Array<class_Array>` **intersect_point_on_canvas** **(** :ref:`Vector2<class_Vector2>` point, :ref:`int<class_int>` canvas_instance_id, :ref:`int<class_int>` max_results=32, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)**
  90. Checks whether a point is inside any solid shape, in a specific canvas layer given by ``canvas_instance_id``. The shapes the point is inside of are returned in an array containing dictionaries with the following fields:
  91. \ ``collider``: The colliding object.
  92. \ ``collider_id``: The colliding object's ID.
  93. \ ``metadata``: The intersecting shape's metadata. This metadata is different from :ref:`Object.get_meta<class_Object_method_get_meta>`, and is set with :ref:`Physics2DServer.shape_set_data<class_Physics2DServer_method_shape_set_data>`.
  94. \ ``rid``: The intersecting object's :ref:`RID<class_RID>`.
  95. \ ``shape``: The shape index of the colliding shape.
  96. The number of intersections can be limited with the ``max_results`` parameter, to reduce the processing time.
  97. Additionally, the method can take an ``exclude`` array of objects or :ref:`RID<class_RID>`\ s that are to be excluded from collisions, a ``collision_mask`` bitmask representing the physics layers to check in, or booleans to determine if the ray should collide with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s or :ref:`Area2D<class_Area2D>`\ s, respectively.
  98. \ **Note:** :ref:`ConcavePolygonShape2D<class_ConcavePolygonShape2D>`\ s and :ref:`CollisionPolygon2D<class_CollisionPolygon2D>`\ s in ``Segments`` build mode are not solid shapes. Therefore, they will not be detected.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_Physics2DDirectSpaceState_method_intersect_ray:
  102. .. rst-class:: classref-method
  103. :ref:`Dictionary<class_Dictionary>` **intersect_ray** **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Array<class_Array>` exclude=[ ], :ref:`int<class_int>` collision_layer=2147483647, :ref:`bool<class_bool>` collide_with_bodies=true, :ref:`bool<class_bool>` collide_with_areas=false **)**
  104. Intersects a ray in a given space. The returned object is a dictionary with the following fields:
  105. \ ``collider``: The colliding object.
  106. \ ``collider_id``: The colliding object's ID.
  107. \ ``metadata``: The intersecting shape's metadata. This metadata is different from :ref:`Object.get_meta<class_Object_method_get_meta>`, and is set with :ref:`Physics2DServer.shape_set_data<class_Physics2DServer_method_shape_set_data>`.
  108. \ ``normal``: The object's surface normal at the intersection point.
  109. \ ``position``: The intersection point.
  110. \ ``rid``: The intersecting object's :ref:`RID<class_RID>`.
  111. \ ``shape``: The shape index of the colliding shape.
  112. If the ray did not intersect anything, then an empty dictionary is returned instead.
  113. Additionally, the method can take an ``exclude`` array of objects or :ref:`RID<class_RID>`\ s that are to be excluded from collisions, a ``collision_mask`` bitmask representing the physics layers to check in, or booleans to determine if the ray should collide with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s or :ref:`Area2D<class_Area2D>`\ s, respectively.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_Physics2DDirectSpaceState_method_intersect_shape:
  117. .. rst-class:: classref-method
  118. :ref:`Array<class_Array>` **intersect_shape** **(** :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` shape, :ref:`int<class_int>` max_results=32 **)**
  119. Checks the intersections of a shape, given through a :ref:`Physics2DShapeQueryParameters<class_Physics2DShapeQueryParameters>` object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields:
  120. \ ``collider``: The colliding object.
  121. \ ``collider_id``: The colliding object's ID.
  122. \ ``metadata``: The intersecting shape's metadata. This metadata is different from :ref:`Object.get_meta<class_Object_method_get_meta>`, and is set with :ref:`Physics2DServer.shape_set_data<class_Physics2DServer_method_shape_set_data>`.
  123. \ ``rid``: The intersecting object's :ref:`RID<class_RID>`.
  124. \ ``shape``: The shape index of the colliding shape.
  125. The number of intersections can be limited with the ``max_results`` parameter, to reduce the processing time.
  126. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  127. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  128. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  129. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`