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.

CollisionPolygon2D

繼承: Node2D < CanvasItem < Node < Object

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

說明

A node that provides a polygon shape to a CollisionObject2D parent and allows it to be edited. The polygon can be concave or convex. This can give a detection shape to an Area2D, turn a 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

Vector2

one_way_collision_direction

Vector2(0, 1)

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()

If true, only edges that face up, relative to CollisionPolygon2D's rotation, will collide with other objects.

Note: This property has no effect if this CollisionPolygon2D is a child of an Area2D node.

Note: The one way collision direction can be configured by setting one_way_collision_direction.


Vector2 one_way_collision_direction = Vector2(0, 1) 🔗

  • void set_one_way_collision_direction(value: Vector2)

  • Vector2 get_one_way_collision_direction()

The direction used for one-way collision.


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.