ConvexPolygonShape2D

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

A 2D convex polygon shape, intended for use in physics. Used internally in CollisionPolygon2D when it's in [Collisionpolygon2d.BuildSolids] mode.

ConvexPolygonShape2D is solid, which means it detects collisions from objects that are fully inside it, unlike ConcavePolygonShape2D which is hollow. This makes it more suitable for both detection and physics.

Convex decomposition: A concave polygon can be split up into several convex polygons. This allows dynamic physics bodies to have complex concave collisions (at a performance cost) and can be achieved by using several ConvexPolygonShape2D nodes or by using the CollisionPolygon2D node in [Collisionpolygon2d.BuildSolids] mode. To generate a collision polygon from a sprite, select the Sprite2D node, go to the Sprite2D menu that appears above the viewport, and choose Create Polygon2D Sibling.

Performance: ConvexPolygonShape2D is faster to check collisions against compared to ConcavePolygonShape2D, but it is slower than primitive collision shapes such as CircleShape2D and RectangleShape2D. Its use should generally be limited to medium-sized objects that cannot have their collision accurately represented by primitive shapes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsConvexPolygonShape2D() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsConvexPolygonShape2D

func (self *Extension[T]) AsConvexPolygonShape2D() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

func (*Extension[T]) AsShape2D

func (self *Extension[T]) AsShape2D() Shape2D.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.ConvexPolygonShape2D

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsConvexPolygonShape2D

func (self Instance) AsConvexPolygonShape2D() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) AsShape2D

func (self Instance) AsShape2D() Shape2D.Instance

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Points

func (self Instance) Points() []Vector2.XY

The polygon's list of vertices that form a convex hull. Can be in either clockwise or counterclockwise order.

Warning: Only set this property to a list of points that actually form a convex hull. Use SetPointCloud to generate the convex hull of an arbitrary set of points.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPointCloud

func (self Instance) SetPointCloud(point_cloud []Vector2.XY)

Based on the set of points provided, this assigns the Points property using the convex hull algorithm, removing all unneeded points. See Geometry2D.ConvexHull for details.

func (Instance) SetPoints

func (self Instance) SetPoints(value []Vector2.XY)

SetPoints sets the property returned by [GetPoints].

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL