Skip to content
0.2.0-dev Download ZIP
148 lines ·10.8 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="PhysicsDirectSpaceState2D" inherits="Object" api_type="core" 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="cast_motion_into">
25 <return type="bool" />
26 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
27 <param index="1" name="result" type="PhysicsCastMotionResult2D" />
28 <description>
29 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.
30 If the query is successful, this method returns [code]true[/code] and writes the motion results into the [PhysicsCastMotionResult2D] object passed in [param result]. If no collision occurs, it returns [code]false[/code].
31 [b]Note:[/b] Any [Shape2D]s that the shape is already colliding with e.g. inside of, will be ignored. Use [method collide_shape_into] to determine the [Shape2D]s that the shape is already colliding with.
32 </description>
33 </method>
34 <method name="collide_shape">
35 <return type="Vector2[]" />
36 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
37 <param index="1" name="max_results" type="int" default="32" />
38 <description>
39 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.
40 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.
41 </description>
42 </method>
43 <method name="collide_shape_into">
44 <return type="bool" />
45 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
46 <param index="1" name="result" type="PhysicsCollideShapeResult2D" />
47 <description>
48 Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space.
49 If intersections are found, this method returns [code]true[/code] and writes the collision points into the [PhysicsCollideShapeResult2D] object passed in [param result]. If no intersections are found, it returns [code]false[/code].
50 The number of returned results can be limited using [member PhysicsCollideShapeResult2D.max_collisions], to reduce the processing time.
51 </description>
52 </method>
53 <method name="get_rest_info">
54 <return type="Dictionary" />
55 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
56 <description>
57 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:
58 [code]collider_id[/code]: The colliding object's ID.
59 [code]linear_velocity[/code]: The colliding object's velocity [Vector2]. If the object is an [Area2D], the result is [code](0, 0)[/code].
60 [code]normal[/code]: The collision normal of the query shape at the intersection point, pointing away from the intersecting object.
61 [code]point[/code]: The intersection point.
62 [code]rid[/code]: The intersecting object's [RID].
63 [code]shape[/code]: The shape index of the colliding shape.
64 If the shape did not intersect anything, then an empty dictionary is returned instead.
65 </description>
66 </method>
67 <method name="get_rest_info_into">
68 <return type="bool" />
69 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
70 <param index="1" name="result" type="PhysicsGetRestInfoResult2D" />
71 <description>
72 Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space.
73 If the shape collides with one or more shapes, this method returns [code]true[/code] and writes the nearest collision information into the [PhysicsGetRestInfoResult2D] object passed in [param result]. If no collisions occur, it returns [code]false[/code].
74 </description>
75 </method>
76 <method name="intersect_point">
77 <return type="Dictionary[]" />
78 <param index="0" name="parameters" type="PhysicsPointQueryParameters2D" />
79 <param index="1" name="max_results" type="int" default="32" />
80 <description>
81 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:
82 [code]collider[/code]: The colliding object.
83 [code]collider_id[/code]: The colliding object's ID.
84 [code]rid[/code]: The intersecting object's [RID].
85 [code]shape[/code]: The shape index of the colliding shape.
86 The number of intersections can be limited with the [param max_results] parameter, to reduce the processing time.
87 [b]Note:[/b] [ConcavePolygonShape2D]s and [CollisionPolygon2D]s in [code]Segments[/code] build mode are not solid shapes. Therefore, they will not be detected.
88 </description>
89 </method>
90 <method name="intersect_point_into">
91 <return type="bool" />
92 <param index="0" name="parameters" type="PhysicsPointQueryParameters2D" />
93 <param index="1" name="result" type="PhysicsIntersectPointResult2D" />
94 <description>
95 Checks whether a point is inside any solid shape. Position and other parameters are defined through [PhysicsPointQueryParameters2D].
96 If one or more shapes overlap the point, this method returns [code]true[/code] and writes the intersection data into the [PhysicsIntersectPointResult2D] object passed in [param result]. If no intersections are found, it returns [code]false[/code].
97 The number of intersections can be limited using [member PhysicsIntersectPointResult2D.max_intersections], to reduce the processing time.
98 [b]Note:[/b] [ConcavePolygonShape2D]s and [CollisionPolygon2D]s in [code]Segments[/code] build mode are not solid shapes. Therefore, they will not be detected.
99 </description>
100 </method>
101 <method name="intersect_ray">
102 <return type="Dictionary" />
103 <param index="0" name="parameters" type="PhysicsRayQueryParameters2D" />
104 <description>
105 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:
106 [code]collider[/code]: The colliding object.
107 [code]collider_id[/code]: The colliding object's ID.
108 [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].
109 [code]position[/code]: The intersection point.
110 [code]rid[/code]: The intersecting object's [RID].
111 [code]shape[/code]: The shape index of the colliding shape.
112 If the ray did not intersect anything, then an empty dictionary is returned instead.
113 </description>
114 </method>
115 <method name="intersect_ray_into">
116 <return type="bool" />
117 <param index="0" name="parameters" type="PhysicsRayQueryParameters2D" />
118 <param index="1" name="result" type="PhysicsIntersectRayResult2D" />
119 <description>
120 Intersects a ray in a given space. Ray position and other parameters are defined through [PhysicsRayQueryParameters2D].
121 If the ray hits a shape, this method returns [code]true[/code] and writes the intersection information into the [PhysicsIntersectRayResult2D] object passed in [param result]. If nothing is hit, it returns [code]false[/code].
122 </description>
123 </method>
124 <method name="intersect_shape">
125 <return type="Dictionary[]" />
126 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
127 <param index="1" name="max_results" type="int" default="32" />
128 <description>
129 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:
130 [code]collider[/code]: The colliding object.
131 [code]collider_id[/code]: The colliding object's ID.
132 [code]rid[/code]: The intersecting object's [RID].
133 [code]shape[/code]: The shape index of the colliding shape.
134 The number of intersections can be limited with the [param max_results] parameter, to reduce the processing time.
135 </description>
136 </method>
137 <method name="intersect_shape_into">
138 <return type="bool" />
139 <param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
140 <param index="1" name="result" type="PhysicsIntersectShapeResult2D" />
141 <description>
142 Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space.
143 If one or more shapes are found to intersect, this method returns [code]true[/code] and writes the intersection data into the [PhysicsIntersectShapeResult2D] object passed in [param result]. If no shapes are found to intersect, it returns [code]false[/code].
144 The number of intersections can be limited using [member PhysicsIntersectShapeResult2D.max_intersections], to reduce the processing time.
145 </description>
146 </method>
147 </methods>
148</class>