CollisionPolygon2D

繼承: Node2D < CanvasItem < Node < Object

CollisionObject2D 父級提供多邊形形狀的節點。

說明

A node that provides a polygon shape to a CollisionObject2D parent and allows to edit it. The polygon can be concave or convex. This can give a detection shape to an Area2D, turn PhysicsBody2D into a solid object, or give a hollow shape to a StaticBody2D.

Warning: A non-uniformly scaled CollisionPolygon2D will likely not behave as expected. Make sure to keep its scale the same on all axes and adjust its polygon instead.

屬性

BuildMode

build_mode

0

bool

disabled

false

bool

one_way_collision

false

float

one_way_collision_margin

1.0

PackedVector2Array

polygon

PackedVector2Array()


列舉

enum BuildMode: 🔗

BuildMode BUILD_SOLIDS = 0

碰撞包含多邊形及其內部區域。在這個模式下,該節點的效果與使用若干 ConvexPolygonShape2D 節點相同,其中的每個節點都包含該多邊形凸分解後的凸形狀(但不會有使用多個節點的負擔)。

BuildMode BUILD_SEGMENTS = 1

碰撞經包含多邊形的邊緣。在這個模式下,該節點的效果與單個由若干線段組成的 ConcavePolygonShape2D 相同,其中(第一條以後的)每條線段都從上一條的終點開始,最後一條線段在第一條的起點結束(構成閉合但中空的多邊形)。


屬性說明

BuildMode build_mode = 0 🔗

Collision build mode.


bool disabled = false 🔗

  • void set_disabled(value: bool)

  • bool is_disabled()

If true, no collisions will be detected. This property should be changed with Object.set_deferred().


bool one_way_collision = false 🔗

  • void set_one_way_collision(value: bool)

  • bool is_one_way_collision_enabled()

如果為 true,則只有面朝上的邊緣才會與其他物件發生碰撞,方向是相對於 CollisionPolygon2D 的旋轉而言的。

注意:如果這個 CollisionPolygon2DArea2D 節點的子節點,則這個屬性無效。


float one_way_collision_margin = 1.0 🔗

  • void set_one_way_collision_margin(value: float)

  • float get_one_way_collision_margin()

用於單向碰撞的邊距(以圖元為單位)。較高的值將使形狀更厚,並且對於以高速進入多邊形的對撞機來說效果更好。


PackedVector2Array polygon = PackedVector2Array() 🔗

The polygon's list of vertices. Each point will be connected to the next, and the final point will be connected to the first.

Note: The returned vertices are in the local coordinate space of the given CollisionPolygon2D.

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