ShapeCast

继承: Item3D < Item < Object

扫描空间区域以检测ColliderObjectBase的3D形状。

描述

形状铸造允许通过沿着target_position确定的铸造方向扫描其shape来检测碰撞物体。这类似于RayCast,但它允许扫描空间区域,而不仅仅是一条直线。ShapeCast可以检测多个碰撞物体。它对宽激光束或将简单形状捕捉到地板等东西很有用。

立即碰撞重叠可以通过将target_position设置为Vector3(0,0,0)并在同一物理帧内调用force_shapecast_update()来完成。这有助于克服AreaTrigger用作瞬时检测区域时的一些限制,因为碰撞信息不能立即提供给它。

注意:形状铸造比光线铸造在计算上更昂贵。

属性

方法


属性说明

bool collide_with_areas = false 🔗

  • void set_collide_with_areas(value: bool)

  • bool is_collide_with_areas_enabled()

如果true,则会报告与AreaTrigger的冲突。


bool collide_with_bodies = true 🔗

  • void set_collide_with_bodies(value: bool)

  • bool is_collide_with_bodies_enabled()

如果true,则会报告与PhysicsBulkBase的冲突。


int collision_mask = 1 🔗

  • void set_collision_mask(value: int)

  • int get_collision_mask()

形状的碰撞掩码。只有在掩码中启用的至少一个碰撞层中的对象才会被检测到。有关详细信息,请参阅文档中的碰撞层和掩码


Array collision_result = [] 🔗

  • Array get_collision_result()

从碰撞扫描返回完整的碰撞信息。返回的数据与PhysicsDirectSpaceState3D.get_rest_info()方法中的数据相同。


Color debug_shape_custom_color = Color(0, 0, 0, 1) 🔗

  • void set_debug_shape_custom_color(value: Color)

  • Color get_debug_shape_custom_color()

如果Debug菜单中启用了可见碰撞形状,则在运行时用于在编辑器中绘制形状的自定义颜色。如果ShapeCast与某物碰撞,此颜色将在运行时突出显示。

如果设置为Color(0.0,0.0,0.0)(默认情况下),则使用ProjectSettings.debug/shapes/collision/shape_color中设置的颜色。


bool enabled = true 🔗

  • void set_enabled(value: bool)

  • bool is_enabled()

如果true,则会报告冲突。


bool exclude_parent = true 🔗

  • void set_exclude_parent_body(value: bool)

  • bool get_exclude_parent_body()

如果true,则父节点将被排除在冲突检测之外。


float margin = 0.0 🔗

  • void set_margin(value: float)

  • float get_margin()

形状的碰撞余量。较大的余量有助于以精度为代价更一致地检测碰撞。


int max_results = 32 🔗

  • void set_max_results(value: int)

  • int get_max_results()

可以使用此参数限制交叉点的数量,以减少流转时长。


Shape3D shape 🔗

用于冲突查询的形状。


Vector3 target_position = Vector3(0, -1, 0) 🔗

  • void set_target_position(value: Vector3)

  • Vector3 get_target_position()

形状的目标点,相对于该节点的Item3D.position


方法说明

void add_exception(node: ColliderObjectBase) 🔗

添加冲突异常,以便形状不报告与指定节点的冲突。


void add_exception_rid(rid: RID) 🔗

添加冲突异常,以便形状不报告与指定RID的冲突。


void clear_exceptions() 🔗

删除此形状的所有冲突异常。


void force_shapecast_update() 🔗

立即更新形状的冲突信息,无需等待下一次_physics_process调用。例如,当形状或其父形状更改状态时,请使用此方法。

注意:不需要将enabled设置为true即可工作。


float get_closest_collision_safe_fraction() const 🔗

返回从该造型的原点到其target_position的形状可以移动多远而不会触发冲突的分数,作为0.01.0之间的值。


float get_closest_collision_unsafe_fraction() const 🔗

返回从该造型的原点到其target_position的形状必须移动多远才能触发碰撞的分数,作为0.01.0之间的值。

在理想条件下,这将与get_closest_collision_safe_fraction()相同,但是形状铸造是以离散的步骤计算的,因此精确的碰撞点可以发生在两个计算位置之间。


Object get_collider(index: int) const 🔗

返回index处多个碰撞之一的碰撞Object,如果没有对象与形状相交,则返回null(即is_colliding()返回false)。


RID get_collider_rid(index: int) const 🔗

返回index处的多个碰撞之一的碰撞对象的RID


int get_collider_shape(index: int) const 🔗

返回index处多个碰撞之一的碰撞形状的形状ID,如果没有对象与该形状相交,则返回0(即is_colliding()返回false)。


int get_collision_count() const 🔗

在撞击点检测到的碰撞数。使用它来迭代get_collider()get_collider_shape()get_collision_point()get_collision_normal()方法提供的多个碰撞。


bool get_collision_mask_value(layer_number: int) const 🔗

返回collision_mask的指定层是否启用,给定介于1和32之间的layer_number


Vector3 get_collision_normal(index: int) const 🔗

返回相交对象index处多个碰撞之一的法线。


Vector3 get_collision_point(index: int) const 🔗

返回形状与碰撞对象相交的index处的多个碰撞之一的碰撞点。

注:此点在全局坐标系中。


bool is_colliding() const 🔗

返回是否有任何对象与形状的向量相交(考虑向量长度)。


void remove_exception(node: ColliderObjectBase) 🔗

删除冲突异常,以便形状确实报告与指定节点的冲突。


void remove_exception_rid(rid: RID) 🔗

删除冲突异常,以便形状确实报告与指定RID的冲突。


void resource_changed(resource: Resource) 🔗

已弃用: 请改用 Resource.changed

这种方法什么也不做。


void set_collision_mask_value(layer_number: int, value: bool) 🔗

基于value,启用或禁用collision_mask中的指定层,给定1到32之间的layer_number