| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="PhysicsDirectSpaceState2D" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Provides direct access to a physics space in the [PhysicsServer2D]. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | Provides direct access to a physics space in the [PhysicsServer2D]. It's used mainly to do queries against objects and areas residing in a given space. |
| 8 | [b]Note:[/b] This class is not meant to be instantiated directly. Use [member World2D.direct_space_state] to get the world's physics 2D space state. |
| 9 | </description> |
| 10 | <tutorials> |
| 11 | <link title="Physics introduction">$DOCS_URL/tutorials/physics/physics_introduction.html</link> |
| 12 | <link title="Ray-casting">$DOCS_URL/tutorials/physics/ray-casting.html</link> |
| 13 | </tutorials> |
| 14 | <methods> |
| 15 | <method name="cast_motion"> |
| 16 | <return type="PackedFloat32Array" /> |
| 17 | <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" /> |
| 18 | <description> |
| 19 | Checks how far a [Shape2D] can move without colliding. All the parameters for the query, including the shape and the motion, are supplied through a [PhysicsShapeQueryParameters2D] object. |
| 20 | 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 [code][1.0, 1.0][/code] will be returned. |
| 21 | [b]Note:[/b] Any [Shape2D]s that the shape is already colliding with e.g. inside of, will be ignored. Use [method collide_shape] to determine the [Shape2D]s that the shape is already colliding with. |
| 22 | </description> |
| 23 | </method> |
| 24 | <method name="collide_shape"> |
| 25 | <return type="Vector2[]" /> |
| 26 | <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" /> |
| 27 | <param index="1" name="max_results" type="int" default="32" /> |
| 28 | <description> |
| 29 | Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space. The resulting array contains a list of points where the shape intersects another. Like with [method intersect_shape], the number of returned results can be limited to save processing time. |
| 30 | Returned points are a list of pairs of contact points. For each pair the first one is in the shape passed in [PhysicsShapeQueryParameters2D] object, second one is in the collided shape from the physics space. |
| 31 | </description> |
| 32 | </method> |
| 33 | <method name="get_rest_info"> |
| 34 | <return type="Dictionary" /> |
| 35 | <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" /> |
| 36 | <description> |
| 37 | Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space. If it collides with more than one shape, the nearest one is selected. The returned object is a dictionary containing the following fields: |
| 38 | [code]collider_id[/code]: The colliding object's ID. |
| 39 | [code]linear_velocity[/code]: The colliding object's velocity [Vector2]. If the object is an [Area2D], the result is [code](0, 0)[/code]. |
| 40 | [code]normal[/code]: The collision normal of the query shape at the intersection point, pointing away from the intersecting object. |
| 41 | [code]point[/code]: The intersection point. |
| 42 | [code]rid[/code]: The intersecting object's [RID]. |
| 43 | [code]shape[/code]: The shape index of the colliding shape. |
| 44 | If the shape did not intersect anything, then an empty dictionary is returned instead. |
| 45 | </description> |
| 46 | </method> |
| 47 | <method name="intersect_point"> |
| 48 | <return type="Dictionary[]" /> |
| 49 | <param index="0" name="parameters" type="PhysicsPointQueryParameters2D" /> |
| 50 | <param index="1" name="max_results" type="int" default="32" /> |
| 51 | <description> |
| 52 | Checks whether a point is inside any solid shape. Position and other parameters are defined through [PhysicsPointQueryParameters2D]. The shapes the point is inside of are returned in an array containing dictionaries with the following fields: |
| 53 | [code]collider[/code]: The colliding object. |
| 54 | [code]collider_id[/code]: The colliding object's ID. |
| 55 | [code]rid[/code]: The intersecting object's [RID]. |
| 56 | [code]shape[/code]: The shape index of the colliding shape. |
| 57 | The number of intersections can be limited with the [param max_results] parameter, to reduce the processing time. |
| 58 | [b]Note:[/b] [ConcavePolygonShape2D]s and [CollisionPolygon2D]s in [code]Segments[/code] build mode are not solid shapes. Therefore, they will not be detected. |
| 59 | </description> |
| 60 | </method> |
| 61 | <method name="intersect_ray"> |
| 62 | <return type="Dictionary" /> |
| 63 | <param index="0" name="parameters" type="PhysicsRayQueryParameters2D" /> |
| 64 | <description> |
| 65 | Intersects a ray in a given space. Ray position and other parameters are defined through [PhysicsRayQueryParameters2D]. The returned object is a dictionary with the following fields: |
| 66 | [code]collider[/code]: The colliding object. |
| 67 | [code]collider_id[/code]: The colliding object's ID. |
| 68 | [code]normal[/code]: The object's surface normal at the intersection point, or [code]Vector2(0, 0)[/code] if the ray starts inside the shape and [member PhysicsRayQueryParameters2D.hit_from_inside] is [code]true[/code]. |
| 69 | [code]position[/code]: The intersection point. |
| 70 | [code]rid[/code]: The intersecting object's [RID]. |
| 71 | [code]shape[/code]: The shape index of the colliding shape. |
| 72 | If the ray did not intersect anything, then an empty dictionary is returned instead. |
| 73 | </description> |
| 74 | </method> |
| 75 | <method name="intersect_shape"> |
| 76 | <return type="Dictionary[]" /> |
| 77 | <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" /> |
| 78 | <param index="1" name="max_results" type="int" default="32" /> |
| 79 | <description> |
| 80 | Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields: |
| 81 | [code]collider[/code]: The colliding object. |
| 82 | [code]collider_id[/code]: The colliding object's ID. |
| 83 | [code]rid[/code]: The intersecting object's [RID]. |
| 84 | [code]shape[/code]: The shape index of the colliding shape. |
| 85 | The number of intersections can be limited with the [param max_results] parameter, to reduce the processing time. |
| 86 | </description> |
| 87 | </method> |
| 88 | </methods> |
| 89 | </class> |