PhysicsDirectSpaceState2D
Inherits: Object
Inherited by: PhysicsDirectSpaceState2DExtension
Description
Section titled “Description”Provides direct access to a physics space in the PhysicsSystem2D.
Provides direct access to a physics space in the PhysicsSystem2D. It’s used mainly to do queries against objects and areas residing in a given space.
Note: This class is not meant to be instantiated directly. Use World2D.direct_space_state to get the world’s physics 2D space state.
Methods
Section titled “Methods”Method descriptions
Section titled “Method descriptions”cast_motion
PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters2D)
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.
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.
Note: Any Shape2Ds that the shape is already colliding with e.g. inside of, will be ignored. Use collide_shape() to determine the Shape2Ds that the shape is already colliding with.
cast_motion_into
bool cast_motion_into(parameters: PhysicsShapeQueryParameters2D, result: PhysicsCastMotionResult2D)
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.
If the query is successful, this method returns true and writes the motion results into the PhysicsCastMotionResult2D object passed in result. If no collision occurs, it returns false.
Note: Any Shape2Ds that the shape is already colliding with e.g. inside of, will be ignored. Use collide_shape_into() to determine the Shape2Ds that the shape is already colliding with.
collide_shape
Array[Vector2] collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32)
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 intersect_shape(), the number of returned results can be limited to save processing time.
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.
collide_shape_into
bool collide_shape_into(parameters: PhysicsShapeQueryParameters2D, result: PhysicsCollideShapeResult2D)
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters2D object, against the space.
If intersections are found, this method returns true and writes the collision points into the PhysicsCollideShapeResult2D object passed in result. If no intersections are found, it returns false.
The number of returned results can be limited using PhysicsCollideShapeResult2D.max_collisions, to reduce the processing time.
get_rest_info
Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters2D)
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:
collider_id: The colliding object’s ID.
linear_velocity: The colliding object’s velocity Vector2. If the object is an Area2D, the result is (0, 0).
normal: The collision normal of the query shape at the intersection point, pointing away from the intersecting object.
point: The intersection point.
rid: The intersecting object’s RID.
shape: The shape index of the colliding shape.
If the shape did not intersect anything, then an empty dictionary is returned instead.
get_rest_info_into
bool get_rest_info_into(parameters: PhysicsShapeQueryParameters2D, result: PhysicsGetRestInfoResult2D)
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters2D object, against the space.
If the shape collides with one or more shapes, this method returns true and writes the nearest collision information into the PhysicsGetRestInfoResult2D object passed in result. If no collisions occur, it returns false.
intersect_point
Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int = 32)
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:
collider: The colliding object.
collider_id: The colliding object’s ID.
rid: The intersecting object’s RID.
shape: The shape index of the colliding shape.
The number of intersections can be limited with the max_results parameter, to reduce the processing time.
Note: ConcavePolygonShape2Ds and CollisionPolygon2Ds in Segments build mode are not solid shapes. Therefore, they will not be detected.
intersect_point_into
bool intersect_point_into(parameters: PhysicsPointQueryParameters2D, result: PhysicsIntersectPointResult2D)
Checks whether a point is inside any solid shape. Position and other parameters are defined through PhysicsPointQueryParameters2D.
If one or more shapes overlap the point, this method returns true and writes the intersection data into the PhysicsIntersectPointResult2D object passed in result. If no intersections are found, it returns false.
The number of intersections can be limited using PhysicsIntersectPointResult2D.max_intersections, to reduce the processing time.
Note: ConcavePolygonShape2Ds and CollisionPolygon2Ds in Segments build mode are not solid shapes. Therefore, they will not be detected.
intersect_ray
Dictionary intersect_ray(parameters: PhysicsRayQueryParameters2D)
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:
collider: The colliding object.
collider_id: The colliding object’s ID.
normal: The object’s surface normal at the intersection point, or Vector2(0, 0) if the ray starts inside the shape and PhysicsRayQueryParameters2D.hit_from_inside is true.
position: The intersection point.
rid: The intersecting object’s RID.
shape: The shape index of the colliding shape.
If the ray did not intersect anything, then an empty dictionary is returned instead.
intersect_ray_into
bool intersect_ray_into(parameters: PhysicsRayQueryParameters2D, result: PhysicsIntersectRayResult2D)
Intersects a ray in a given space. Ray position and other parameters are defined through PhysicsRayQueryParameters2D.
If the ray hits a shape, this method returns true and writes the intersection information into the PhysicsIntersectRayResult2D object passed in result. If nothing is hit, it returns false.
intersect_shape
Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32)
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:
collider: The colliding object.
collider_id: The colliding object’s ID.
rid: The intersecting object’s RID.
shape: The shape index of the colliding shape.
The number of intersections can be limited with the max_results parameter, to reduce the processing time.
intersect_shape_into
bool intersect_shape_into(parameters: PhysicsShapeQueryParameters2D, result: PhysicsIntersectShapeResult2D)
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters2D object, against the space.
If one or more shapes are found to intersect, this method returns true and writes the intersection data into the PhysicsIntersectShapeResult2D object passed in result. If no shapes are found to intersect, it returns false.
The number of intersections can be limited using PhysicsIntersectShapeResult2D.max_intersections, to reduce the processing time.
