Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

PhysicsDirectSpaceState3D

继承: Object

派生: PhysicsDirectSpaceState3DExtension

提供对 PhysicsServer3D 中物理空间的直接访问。

描述

提供对 PhysicsServer3D 中物理空间的直接访问。主要用于对驻留在给定空间中的对象和区域进行查询。

教程

方法

PackedFloat32Array

cast_motion ( PhysicsShapeQueryParameters3D parameters )

Vector3[]

collide_shape ( PhysicsShapeQueryParameters3D parameters, int max_results=32 )

Dictionary

get_rest_info ( PhysicsShapeQueryParameters3D parameters )

Dictionary[]

intersect_point ( PhysicsPointQueryParameters3D parameters, int max_results=32 )

Dictionary

intersect_ray ( PhysicsRayQueryParameters3D parameters )

Dictionary[]

intersect_shape ( PhysicsShapeQueryParameters3D parameters, int max_results=32 )


方法说明

PackedFloat32Array cast_motion ( PhysicsShapeQueryParameters3D parameters )

检查 Shape3D 在不发生碰撞的情况下可以移动多远。查询的所有参数,包括形状,都通过 PhysicsShapeQueryParameters3D 对象提供。

返回一个数组,其中包含运动的安全和不安全比例(介于 0 和 1 之间)。安全比例是在不发生碰撞的情况下可以进行的运动的最大分数。不安全比例是发生碰撞必须移动的距离的最小分数。如果没有检测到碰撞,将返回 [1.0, 1.0] 的结果。

注意:该形状已经与之发生碰撞的任何 Shape3D,例如在内部的,将被忽略。使用 collide_shape 来确定该形状已经与之发生碰撞的 Shape3D


Vector3[] collide_shape ( PhysicsShapeQueryParameters3D parameters, int max_results=32 )

检查通过 PhysicsShapeQueryParameters3D 对象给出的一个形状与该空间的交点。结果数组包含该形状与另一个形状相交处的点的列表。与 intersect_shape 一样,可以限制返回结果的数量以节省处理时间。

返回的点是接触点对的一个列表。对于每一对,第一个是在 PhysicsShapeQueryParameters3D 对象中传递的形状,第二个是来自物理空间的碰撞形状。

注意:该方法不考虑对象的 motion 属性。


Dictionary get_rest_info ( PhysicsShapeQueryParameters3D parameters )

检查通过 PhysicsShapeQueryParameters3D 对象给出的形状与该空间的交点。如果它与多个形状发生碰撞,则选择最近的一个。返回的对象是一个包含以下字段的字典:

collider_id:该碰撞对象的 ID。

linear_velocity:该碰撞对象的速度 Vector3。如果对象是一个 Area3D,则结果为 (0, 0, 0)

normal:该交点处物体的表面法线。

point:该相交点。

rid:该相交对象的 RID

shape:该碰撞形状的形状索引。

如果该形状没有与任何东西相交,则返回一个空字典。

注意:该方法不考虑对象的 motion 属性。


Dictionary[] intersect_point ( PhysicsPointQueryParameters3D parameters, int max_results=32 )

检查点是否在任何实体形状内。位置和其他参数通过 PhysicsPointQueryParameters3D 定义。点所在的形状会以数组的形式返回,该数组包含有以下字段的字典:

collider:碰撞对象。

collider_id:碰撞对象的 ID。

rid:相交对象的RID

shape:碰撞形状的形状索引。

可以使用 max_results 参数限制相交的数量,以减少处理时间。


Dictionary intersect_ray ( PhysicsRayQueryParameters3D parameters )

在给定空间中检测与射线的相交情况。射线的位置和其他参数由 PhysicsRayQueryParameters3D 定义。返回的对象是包含以下字段的字典:

collider:碰撞到的对象。

collider_id:碰撞到的对象的 ID。

normal:该对象表面交点处的法线,如果射线中该形状的内部开始,并且 PhysicsRayQueryParameters3D.hit_from_insidetrue,则为 Vector3(0, 0, 0)

position:交点。

face_index:交点处的面索引。

注意:只有相交形状是 ConcavePolygonShape3D 时才会返回有效值。否则返回 -1

rid:相交对象的 RID

shape:碰撞形状的形状索引。

如果射线没有发生相交,则返回的是空字典。


Dictionary[] intersect_shape ( PhysicsShapeQueryParameters3D parameters, int max_results=32 )

检查通过 PhysicsShapeQueryParameters3D 对象给出的形状与空间的交点。相交的形状在包含具有以下字段的字典的数组中返回:

collider:碰撞对象。

collider_id:碰撞对象的 ID。

rid:相交对象的 RID

shape:碰撞形状的形状索引。

可以使用 max_results 参数限制相交的数量,以减少处理时间。

注意:该方法不考虑对象的 motion 属性。