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...
ShapeCast3D
3D 形狀,會掃描空間中某個區域,用於偵測 CollisionObject3D。
說明
形狀投射會將其 shape 沿著 target_position 確定的投射方向進行掃描,能夠偵測到碰撞物件。類似於 RayCast3D,但是能夠掃描空間中的一個區域,而不僅僅是一條直線。ShapeCast3D 能夠偵測到多個碰撞物件。可用於實作較寬的鐳射射線,或者將簡單的形狀吸附到地面。
要立即偵測碰撞重疊,可以將 target_position 設定為 Vector3(0, 0, 0),並在同一個物理影格中呼叫 force_shapecast_update()。這樣就能夠克服 Area3D 在進行連續區域偵測時的局限性,因為它無法立即取得碰撞資訊。
注意:形狀投射比射線投射的計算量更大。
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
void |
add_exception(node: CollisionObject3D) |
void |
add_exception_rid(rid: RID) |
void |
|
void |
|
get_collider(index: int) const |
|
get_collider_rid(index: int) const |
|
get_collider_shape(index: int) const |
|
get_collision_count() const |
|
get_collision_mask_value(layer_number: int) const |
|
get_collision_normal(index: int) const |
|
get_collision_point(index: int) const |
|
is_colliding() const |
|
void |
|
void |
remove_exception_rid(rid: RID) |
void |
resource_changed(resource: Resource) |
void |
set_collision_mask_value(layer_number: int, value: bool) |
屬性說明
bool collide_with_areas = false 🔗
如果為 true,則會報告與 Area3D 的碰撞。
bool collide_with_bodies = true 🔗
如果為 true,則會報告與 PhysicsBody3D 的碰撞。
形狀的碰撞遮罩。只有至少啟用了一個在該遮罩中的碰撞層的物件才會被偵測到。有關詳細資訊,請參閱文件中的《碰撞層和遮罩》。
Array get_collision_result()
從碰撞掃描返回完整的碰撞資訊。返回的資料與 PhysicsDirectSpaceState3D.get_rest_info() 方法中的資料相同。
Color debug_shape_custom_color = Color(0, 0, 0, 1) 🔗
如果在除錯功能表中啟用了可見碰撞形狀,則用於在編輯器中和運作時中繪製形狀的自訂顏色。如果 ShapeCast3D 與某物發生碰撞,該顏色將在運作時突出顯示。
如果設定為 Color(0.0, 0.0, 0.0)(預設值),則使用 ProjectSettings.debug/shapes/collision/shape_color 中設定的顏色。
如果為 true,將報告碰撞。
如果為 true,父節點將被排除在碰撞偵測之外。
該形狀的碰撞邊距。較大的邊距有助於更一致地偵測碰撞,但代價是犧牲精度。
可以使用這個參數來限制相交點的數量,減少處理時間。
用於碰撞查詢的形狀。
Vector3 target_position = Vector3(0, -1, 0) 🔗
形狀的目標點,相對於該節點的 Node3D.position。
方法說明
void add_exception(node: CollisionObject3D) 🔗
新增碰撞例外,使該形狀不彙報與指定節點的碰撞。
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.0 到 1.0 之間的值。
float get_closest_collision_unsafe_fraction() const 🔗
回傳從投射原點到 target_position 之間的分數,形狀移動多遠才能夠觸發碰撞,是一個 0.0 到 1.0 之間的值。
在理想條件下與 get_closest_collision_safe_fraction() 相同,但是形狀投射是分步驟計算的,因此精確的碰撞點可能發生在兩個計算位置之間。
Object get_collider(index: int) const 🔗
返回 index 處多次碰撞之一的碰撞 Object,如果沒有物件與形狀相交(即 is_colliding() 返回 false),則返回 null。
RID get_collider_rid(index: int) const 🔗
返回 index 處多次碰撞之一的碰撞物件的 RID。
int get_collider_shape(index: int) const 🔗
返回 index 處多次碰撞之一的碰撞形狀的形狀 ID,如果沒有物件與該形狀相交(即 is_colliding() 返回 false),則返回 0。
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 中是否啟用了指定的層,給定的 layer_number 應在 1 和 32 之間。
Vector3 get_collision_normal(index: int) const 🔗
返回相交物件 index 處多次碰撞之一的法線。
Vector3 get_collision_point(index: int) const 🔗
回傳形狀與碰撞物件相交的 index 處多次碰撞之一的碰撞點。
注意:這個點使用全域座標系。
返回是否有任何物件與形狀的向量相交(考慮向量長度)。
void remove_exception(node: CollisionObject3D) 🔗
移除碰撞例外,使該形狀能夠彙報與指定節點的碰撞。
void remove_exception_rid(rid: RID) 🔗
移除碰撞例外,使該形狀能夠彙報與指定 RID 的碰撞。
void resource_changed(resource: Resource) 🔗
已棄用: Use Resource.changed instead.
這個方法甚麼也不做。
void set_collision_mask_value(layer_number: int, value: bool) 🔗
根據 value,啟用或停用 collision_mask 中指定的層,給定的 layer_number 應在 1 和 32 之間。