PhysicsDirectSpaceState3D
继承: Object
派生: PhysicsDirectSpaceState3DExtension
提供对 PhysicsServer3D 中物理空间的直接访问。
描述
提供对 PhysicsServer3D 中物理空间的直接访问。主要用于对驻留在给定空间中的对象和区域进行查询。
注意:该类不应直接实例化。请使用 World3D.direct_space_state 获取世界的 3D 物理空间状态。
教程
方法
cast_motion(parameters: PhysicsShapeQueryParameters3D) |
|
collide_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) |
|
get_rest_info(parameters: PhysicsShapeQueryParameters3D) |
|
intersect_point(parameters: PhysicsPointQueryParameters3D, max_results: int = 32) |
|
intersect_ray(parameters: PhysicsRayQueryParameters3D) |
|
intersect_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) |
方法说明
PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters3D) 🔗
检查 Shape3D 能够在不发生碰撞的情况下移动多远。包括形状和运动在内的所有查询参数都通过 PhysicsShapeQueryParameters3D 对象提供。
返回包含该运动的安全和不安全比例(在 0 和 1 之间)的数组。安全比例是该运动能够不发生碰撞的最大分数。不安全比例是发生碰撞所需的最小分数。如果没有检测到碰撞,则返回的结果为 [1.0, 1.0]。
注意:该形状已碰撞的 Shape3D 会被忽略,例如形状在其内部。请使用 collide_shape() 确定该形状已碰撞的 Shape3D。
Array[Vector3] collide_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) 🔗
检查通过 PhysicsShapeQueryParameters3D 对象给出的一个形状与该空间的交点。结果数组包含该形状与另一个形状相交处的点的列表。与 intersect_shape() 一样,可以限制返回结果的数量以节省处理时间。
返回的点是接触点对的一个列表。对于每一对,第一个是在 PhysicsShapeQueryParameters3D 对象中传递的形状,第二个是来自物理空间的碰撞形状。
注意:该方法不考虑对象的 motion 属性。
Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters3D) 🔗
检查通过 PhysicsShapeQueryParameters3D 对象给出的形状与该空间的交点。如果它与多个形状发生碰撞,则选择最近的一个。返回的对象是一个包含以下字段的字典:
collider_id:该碰撞对象的 ID。
linear_velocity:该碰撞对象的速度 Vector3。如果对象是一个 Area3D,则结果为 (0, 0, 0)。
normal:相交点处查询形状的碰撞法线,法线指向远离相交对象的方向。
point:相交点。
rid:该相交对象的 RID。
shape:该碰撞形状的形状索引。
如果该形状没有与任何东西相交,则返回一个空字典。
注意:该方法不考虑对象的 motion 属性。
Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters3D, max_results: int = 32) 🔗
检查点是否在任何实体形状内。位置和其他参数通过 PhysicsPointQueryParameters3D 定义。点所在的形状会以数组的形式返回,该数组包含有以下字段的字典:
collider:碰撞对象。
collider_id:碰撞对象的 ID。
rid:相交对象的RID。
shape:碰撞形状的形状索引。
可以使用 max_results 参数限制相交的数量,以减少处理时间。
Dictionary intersect_ray(parameters: PhysicsRayQueryParameters3D) 🔗
在给定空间中检测与射线的相交情况。射线的位置和其他参数由 PhysicsRayQueryParameters3D 定义。返回的对象是包含以下字段的字典:
collider:碰撞到的对象。
collider_id:碰撞到的对象的 ID。
normal:该对象表面交点处的法线,如果射线中该形状的内部开始,并且 PhysicsRayQueryParameters3D.hit_from_inside 为 true,则为 Vector3(0, 0, 0)。
position:交点。
face_index:交点处的面索引。
注意:只有相交形状是 ConcavePolygonShape3D 时才会返回有效值。否则返回 -1。
rid:相交对象的 RID。
shape:碰撞形状的形状索引。
如果射线没有发生相交,则返回的是空字典。
Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) 🔗
检查通过 PhysicsShapeQueryParameters3D 对象给出的形状与空间的交点。相交的形状在包含具有以下字段的字典的数组中返回:
collider:碰撞对象。
collider_id:碰撞对象的 ID。
rid:相交对象的 RID。
shape:碰撞形状的形状索引。
可以使用 max_results 参数限制相交的数量,以减少处理时间。
注意:该方法不考虑对象的 motion 属性。