ConvexPolygonShape2D
繼承: Shape2D < Resource < RefCounted < Object
用於物理碰撞的 2D 凸多邊形形狀。
說明
2D 凸多邊形形狀,旨在用於物理。CollisionPolygon2D 為 BUILD_SOLIDS 模式時內部會使用這個類。
ConvexPolygonShape2D 是實心的,與空心的 ConcavePolygonShape2D 不同,如果物件完全位於其內部,也能夠偵測到碰撞。因此更適於偵測和物理。
凸分解:凹多邊形可以拆分為多個凸多邊形。這樣就能夠讓動態物理體擁有複雜的凹碰撞(以消耗性能為代價),做法是使用多個 ConvexPolygonShape3D 節點,或者使用 BUILD_SOLIDS 模式的 CollisionPolygon2D 節點。要根據精靈生成碰撞多邊形,請選中 Sprite2D 節點,前往出現在視口上方的 Sprite2D 功能表,然後選擇建立 Polygon2D 同級。
性能:ConvexPolygonShape2D 檢查碰撞的速度比 ConcavePolygonShape2D 要快,但比 CircleShape2D、RectangleShape2D 等基本碰撞形狀要慢。通常應該僅限於中等大小的物件,在無法使用基本形狀精確表示碰撞時使用。
屬性
|
方法
void |
set_point_cloud(point_cloud: PackedVector2Array) |
屬性說明
PackedVector2Array points = PackedVector2Array() 🔗
void set_points(value: PackedVector2Array)
PackedVector2Array get_points()
該多邊形構成凸包的頂點列表。順時針順序或逆時針順序都有可能。
警告:請務必將這個屬性設定為能夠形成凸包的頂點列表。可以使用 set_point_cloud() 從任意頂點集生成凸包。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.
方法說明
void set_point_cloud(point_cloud: PackedVector2Array) 🔗
根據提供的點集,使用凸包演算法分配 points 屬性,移除所有不必要的點。詳見 Geometry2D.convex_hull()。