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...
ConvexPolygonShape2D
继承: Shape2D < Resource < RefCounted < Object
用于物理碰撞的 2D 凸多边形形状。
描述
2D 凸多边形形状,旨在用于物理。CollisionPolygon2D 为 CollisionPolygon2D.BUILD_SOLIDS 模式时内部会使用这个类。
ConvexPolygonShape2D 是实心的,与空心的 ConcavePolygonShape2D 不同,如果对象完全位于其内部,也能够检测到碰撞。因此更适于检测和物理。
凸分解:凹多边形可以拆分为多个凸多边形。这样就能够让动态物理体拥有复杂的凹碰撞(以消耗性能为代价),做法是使用多个 ConvexPolygonShape3D 节点,或者使用 CollisionPolygon2D.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()。