Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
PhysicsDirectSpaceState2D
继承: Object
派生: PhysicsDirectSpaceState2DExtension
提供对 PhysicsServer2D 中物理空间的直接访问。
描述
提供对 PhysicsServer2D 中物理空间的直接访问。主要用于对驻留在给定空间中的对象和区域进行查询。
教程
方法
cast_motion(parameters: PhysicsShapeQueryParameters2D) |
|
collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) |
|
get_rest_info(parameters: PhysicsShapeQueryParameters2D) |
|
intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int = 32) |
|
intersect_ray(parameters: PhysicsRayQueryParameters2D) |
|
intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) |
方法说明
PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters2D) 🔗
检查 Shape2D 能够在不发生碰撞的情况下移动多远。包括形状和运动在内的所有查询参数都通过 PhysicsShapeQueryParameters2D 对象提供。
返回包含该运动的安全和不安全比例(在 0 和 1 之间)的数组。安全比例是该运动能够不发生碰撞的最大分数。不安全比例是发生碰撞所需的最小分数。如果没有检测到碰撞,则返回的结果为 [1.0, 1.0]
。
注意:该形状已碰撞的 Shape2D 会被忽略,例如形状在其内部。请使用 collide_shape() 确定该形状已碰撞的 Shape2D。
Array[Vector2] collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) 🔗
检查通过 PhysicsShapeQueryParameters2D 对象给出的一个形状与该空间的交点。结果数组包含该形状与另一个形状相交处的点的列表。与 intersect_shape() 一样,可以限制返回结果的数量以节省处理时间。
返回的点是接触点对的一个列表。对于每一对,第一个是在 PhysicsShapeQueryParameters2D 对象中传递的形状,第二个是来自物理空间的碰撞形状。
Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters2D) 🔗
检查通过 PhysicsShapeQueryParameters2D 对象给出的一个形状与该空间的交点。如果它与多个形状碰撞,则选择最近的一个。如果该形状没有与任何对象相交,则返回一个空字典。
注意:该方法不考虑对象的 motion
属性。返回的对象是一个包含以下字段的字典:
collider_id
:该碰撞对象的 ID。
linear_velocity
:该碰撞对象的速度 Vector2。如果对象是一个 Area2D,则结果是 (0, 0)
。
normal
:相交点处查询形状的碰撞法线,法线指向远离相交对象的方向。
point
:相交点。
rid
:相交对象的 RID。
shape
:该碰撞形状的形状索引。
Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int = 32) 🔗
检查点是否在任何实体形状内。位置和其他参数通过 PhysicsPointQueryParameters2D 定义。点所在的形状在包含具有以下字段的字典的数组中返回:
collider
:碰撞对象。
collider_id
:碰撞对象的 ID。
rid
:相交对象的 RID。
shape
:碰撞形状的形状索引。
可以使用 max_results
参数限制相交的数量,以减少处理时间。
注意:在 Segments
构建模式下,ConcavePolygonShape2D 和 CollisionPolygon2D 不是实体形状。因此,它们不会被检测到。
Dictionary intersect_ray(parameters: PhysicsRayQueryParameters2D) 🔗
与一个给定空间中的一个射线相交。射线位置和其他参数通过 PhysicsRayQueryParameters2D 定义。返回的对象是一个包含以下字段的字典:
collider
:该碰撞对象。
collider_id
:该碰撞对象的 ID。
normal
:在相交点处该对象的表面法线;如果射线从形状内部开始,并且 PhysicsRayQueryParameters2D.hit_from_inside 为 true
,则为 Vector2(0, 0)
。
position
:该相交点。
rid
:该相交对象的 RID。
shape
:该碰撞形状的形状索引。
如果射线没有与任何东西相交,则返回一个空字典。
Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) 🔗
检查通过 PhysicsShapeQueryParameters2D 对象给出的形状与空间的交点。相交的形状会以数组的形式返回,该数组包含有以下字段的字典:
collider
:碰撞对象。
collider_id
:碰撞对象的 ID。
rid
:相交对象的RID。
shape
:碰撞形状的形状索引。
可以使用 max_results
参数限制相交的数量,以减少处理时间。