Physics2DDirectSpaceState
Inherits: Object
直接访问Physics2DServer中的空间的对象。
描述
直接访问Physics2DServer中的空间的对象。它主要用于对位于给定空间中的对象和区域进行查询。
教程
方法
cast_motion ( Physics2DShapeQueryParameters shape ) | |
collide_shape ( Physics2DShapeQueryParameters shape, int max_results=32 ) | |
get_rest_info ( Physics2DShapeQueryParameters shape ) | |
intersect_point ( Vector2 point, int max_results=32, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false ) | |
intersect_point_on_canvas ( Vector2 point, int canvas_instance_id, int max_results=32, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false ) | |
intersect_ray ( Vector2 from, Vector2 to, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false ) | |
intersect_shape ( Physics2DShapeQueryParameters shape, int max_results=32 ) |
方法说明
- Array cast_motion ( Physics2DShapeQueryParameters shape )
检查 Shape2D 可以移动多远而不会发生碰撞。查询的所有参数,包括形状和运动,都是通过 Physics2DShapeQueryParameters 对象提供的。
返回一个包含运动的安全和不安全比例(0 到 1 之间)的数组。安全比例是在没有碰撞的情况下可以进行的运动的最大比例。不安全比例是碰撞必须移动的距离的最小部分。如果没有检测到碰撞,将返回 [1.0, 1.0]
的结果。
注意: 任何已经碰撞的Shape2D(比如内部的)会被忽略。使用 collide_shape 确定形状已经碰撞的 Shape2D。
- Array collide_shape ( Physics2DShapeQueryParameters shape, int max_results=32 )
通过Physics2DShapeQueryParameters对象给出的形状与空间的检查交点。结果数组包含一个形状与另一个形状相交的点的列表。像intersect_shape一样,可以限制返回结果的数量以节省处理时间。
- Dictionary get_rest_info ( Physics2DShapeQueryParameters shape )
通过Physics2DShapeQueryParameters对象给出的形状与空间的检查交点。如果它与一个以上的形状发生碰撞,则选择最近的一个。如果该形状没有与任何对象相交,那么将返回一个空字典。
注意: 这个方法不考虑对象的motion
属性。返回的对象是包含以下字段的字典。
collider_id
:碰撞对象的ID。
linear_velocity
:碰撞物体的速度Vector2。如果对象是一个Area2D,结果是(0, 0)
。
metadata
:相交形状的元数据。这个元数据与Object.get_meta不同,它是用Physics2DServer.shape_set_data设置的。
normal
:物体在交点处的表面法线。
point
:相交点。
rid
:相交物体的RID。
shape
:碰撞形状的形状索引。
- Array intersect_point ( Vector2 point, int max_results=32, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false )
检查一个点是否在任意实体形状内。点所处的形状会以数组的形式返回,该数组包含有以下字段的字典:
collider
:碰撞的对象。
collider_id
:碰撞对象的 ID。
metadata
:相交形状的元数据。这个元数据与 Object.get_meta 不同,是用 Physics2DServer.shape_set_data 设置的。
rid
:相交物体的 RID。
shape
:碰撞形状的形状索引。
为了减少处理时间,可以通过 max_results
参数对相交的数量进行限制。
此外,该方法可以接受一个 exclude
数组,该数组中的对象或 RID 将被排除在碰撞之外,collision_mask
位掩码表示要检查的物理层,或者布尔值来确定射线是否应该分别与 PhysicsBody2D 或 Area2D 发生碰撞。
注意:ConcavePolygonShape2D 和 CollisionPolygon2D 在 Segments
构建模式中不是实体形状。因此,它们将不会被检测到。
- Array intersect_point_on_canvas ( Vector2 point, int canvas_instance_id, int max_results=32, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false )
检查一个点是否在任意实体形状内,仅在 canvas_instance_id
所指定的画布层上检查。点所处的形状会以数组的形式返回,该数组包含有以下字段的字典:
collider
:碰撞的对象。
collider_id
:碰撞对象的 ID。
metadata
:相交形状的元数据。这个元数据与 Object.get_meta 不同,是用 Physics2DServer.shape_set_data 设置的。
rid
:相交物体的 RID。
shape
:碰撞形状的形状索引。
为了减少处理时间,可以通过 max_results
参数对相交的数量进行限制。
此外,该方法可以接受一个 exclude
数组,该数组中的对象或 RID 将被排除在碰撞之外,collision_mask
位掩码表示要检查的物理层,或者布尔值来确定射线是否应该分别与 PhysicsBody 或 Area 发生碰撞。
注意:ConcavePolygonShape2D 和 CollisionPolygon2D 在 Segments
构建模式中不是实体形状。因此,它们将不会被检测到。
- Dictionary intersect_ray ( Vector2 from, Vector2 to, Array exclude=[ ], int collision_layer=2147483647, bool collide_with_bodies=true, bool collide_with_areas=false )
在给定的空间中与一条射线相交。返回的对象是具有下列字段的字典:
collider
:碰撞的对象。
collider_id
:碰撞对象的 ID。
metadata
:相交形状的元数据。这个元数据与 Object.get_meta 不同,是用 Physics2DServer.shape_set_data 设置的。
normal
:相交点处对象表面的法线。
position
:相交点。
rid
:相交物体的 RID。
shape
:碰撞形状的形状索引。
如果射线没有与任何东西相交,将返回一个空字典。
此外,该方法可以接受一个 exclude
对象或 RID 数组,该数组将被排除在碰撞之外,collision_mask
位掩码表示要检查的物理层,或者布尔值来确定射线是否应该分别与 PhysicsBody2D 或 Area2D 发生碰撞。
- Array intersect_shape ( Physics2DShapeQueryParameters shape, int max_results=32 )
Checks the intersections of a shape, given through a Physics2DShapeQueryParameters 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.
metadata
: The intersecting shape’s metadata. This metadata is different from Object.get_meta, and is set with Physics2DServer.shape_set_data.
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.