Collider associated with this shape
Get the axis associated with the convex polygon
Get the axis aligned bounding box for the polygon shape in world coordinates
Get the center of the collision shape in world coordinates
Get the moment of inertia for an arbitrary polygon https://en.wikipedia.org/wiki/List_of_moments_of_inertia
Get the axis aligned bounding box for the polygon shape in local coordinates
Returns a clone of this ConvexPolygon, not associated with any collider
Returns a collision contact if the 2 collision shapes collide, otherwise collide will return null.
Tests if a point is contained in this collision shape in world space
Gets the sides of the polygon in world space
Gets the points that make up the polygon in world space, from actor relative space (if specified)
Project the edges of the polygon along a specified axis
Perform Separating Axis test against another polygon, returns null if no overlap in polys Reference http://www.dyn4j.org/2010/01/sat/
Polygon collision shape for detecting collisions
Example:
Box and ConvexPolygon Collision Shapes
Excalibur has a Shape static helper to create boxes and polygons for collisions in your game.
The default shape for a collider is a box, a custom box shape and Collider can be created for an actor body. The
ex.Shape.Box
helper actually creates a ConvexPolygon shape in Excalibur.const block = new ex.Actor({ pos: new ex.Vector(400, 400), color: ex.Color.Red, body: new ex.Body({ collider: new ex.Collider({ shape: ex.Shape.Box(50, 50) type: ex.CollisionType.Active; }) }) });
Creating a custom convex polygon shape is just as simple. Excalibur only supports arbitrary convex shapes as a ConvexPolygon, this means no "cavities" in the shape, for example "pac-man" is not a convex shape.
The
points
in a convex polygon have counter-clockwise winding by default, this means the points must be listed in counter-clockwise order around the shape to work. This can be switched by supplyingtrue
orfalse
to the winding argumentex.Shape.Polygon([...], true)
for clockwise winding.Keep in mind, points are defined local to the body or actor. Meaning that the triangle defined below is centered around
ex.Vector(400, 400)
in world space.const triangle = new ex.Actor({ pos: new ex.Vector(400, 400), color: ex.Color.Red, body: new ex.Body({ collider: new ex.Collider({ shape: ex.Shape.Polygon([new ex.Vector(0, -100), new ex.Vector(-100, 50), new ex.Vector(100, 50)]) type: ex.CollisionType.Active; }) }) });