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.

ConcavePolygonShape2D

繼承: Shape2D < Resource < RefCounted < Object

用於物理碰撞的 2D 多線段形狀。

說明

一種 2D 折線形狀,用於物理運算。當 CollisionPolygon2D 處於 CollisionPolygon2D.BUILD_SEGMENTS 模式時,會在其內部使用。

作為一組相互連接線段,ConcavePolygonShape2D 是最自由的可設定的單一 2D 形狀。它可以用於形成任何性質的多邊形,甚至是不封閉區域的形狀。然而,即使相互連接的線段確實封閉了一個區域,ConcavePolygonShape2D 仍然是中空的,這常常使其不適用於物理模擬或碰撞檢測。

注意:當用於碰撞計算時,ConcavePolygonShape2D 旨在與 StaticBody2D 等靜態 CollisionShape2D 節點一起使用,並且對於 CharacterBody2D 或 RigidBody2D,在除靜態模式之外的其他模式下可能表現不佳。

警告:較小的物理物體在快速移動時有機會穿過該形狀。發生這種情況是因為在一影格上,物理物體可能位於形狀的“外部”,而在下一影格上,它可能位於形狀的“內部”。由於ConcavePolygonShape2D 是中空的,因此它不會檢測到碰撞。

效能:由於其複雜性, ConcavePolygonShape2D 是檢測碰撞最慢的 2D 碰撞形狀。它的使用一般僅限於關卡幾何體。如果折線是閉合的,可以使用 CollisionPolygon2D 的 CollisionPolygon2D.BUILD_SOLIDS 模式,它會將多邊形分解成凸多邊形;相關說明請參閱 ConvexPolygonShape2D 文件。

屬性

PackedVector2Array

segments

PackedVector2Array()


屬性說明

PackedVector2Array segments = PackedVector2Array() 🔗

頂點陣列,構成 ConcavePolygonShape2D 的線段。該(長度能被二整除的)陣列自然兩兩群組(每組代表一條線段);每組都由一條線段的起點和終點構成。

Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.