物理2直接空间状态¶
继承: Object
类别: 核心
简要说明¶
直接访问对象到 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 ) |
描述¶
直接访问对象到 Physics2DServer . 它主要用于查询特定空间中的对象和区域。
方法说明¶
Array cast_motion ( Physics2DShapeQueryParameters shape )
检查形状可向点移动的距离。如果形状不能移动,数组将为空。
注: 形状和运动都是通过 Physics2DShapeQueryParameters 对象。该方法将返回一个数组,其中两个浮点数介于0和1之间,都表示 motion
. 第一个是形状在不触发碰撞的情况下可以移动多远,第二个是发生碰撞的点。如果未检测到冲突,则返回的数组将 [1, 1]
.
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
:碰撞形状的形状索引。
此外,该方法可以采用 exclude
对象数组或 RID 将从碰撞中排除的,a collision_mask
表示要检入的物理层的位掩码,或用于确定光线是否应与之碰撞的布尔值。 PhysicsBody S或 Area 分别是。
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 )
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 将从碰撞中排除的,a collision_mask
表示要检入的物理层的位掩码,或用于确定光线是否应与之碰撞的布尔值。 PhysicsBody S或 Area 分别是。
Array intersect_shape ( Physics2DShapeQueryParameters shape, int max_results=32 )
检查形状的交叉点,通过 Physics2DShapeQueryParameters 物体,对着空间。
注: 此方法不考虑 motion
对象的属性。相交的形状将在包含字典的数组中返回,其中包含以下字段:
collider
:碰撞对象。
collider_id
:碰撞对象的ID。
metadata
:相交形状的元数据。此元数据与 Object.get_meta ,并设置为 Physics2DServer.shape_set_data .
rid
:相交对象的 RID .
shape
:碰撞形状的形状索引。
交叉口的数量可以用 max_results
参数,减少处理时间。