Polygon Collider 2D
Convex polygon of 3 to 8 points.
component physics.PolygonCollider2D
Try it
Polygon collider bounce
The outline follows the triangle collider. With gravity off and Restitution 0, the triangle stops when it strikes the floor.
Change Restitution from 0 to 1 to make the same collision bounce. Reset restores the original contact.
Scene4 nodes
Scriptmain.aes
package demo
import (
"aego/debug"
"aego/physics"
)
// The outline follows the three actual polygon corners. The fixed-speed
// collision makes a change of restitution visible without changing the shape.
script PolygonImpact {
func Ready() {
node.Get<Body2D>().SetVelocity(Vec2{0, 15})
}
func Update(dt float) {
p := node.WorldPosition()
top := Vec2{p.X, p.Y - 0.8}
right := Vec2{p.X + 0.8, p.Y + 0.6}
left := Vec2{p.X - 0.8, p.Y + 0.6}
color := Color{1, 0.65, 0.1, 1}
// Several closely spaced strokes keep the exact outline readable in
// the small embedded Game View as well as the native editor.
for i := -2; i <= 2; i++ {
x := float(i) * 0.08
debug.Line(Vec2{top.X + x, top.Y}, Vec2{right.X + x, right.Y}, color)
debug.Line(Vec2{right.X + x, right.Y}, Vec2{left.X + x, left.Y}, color)
debug.Line(Vec2{left.X + x, left.Y}, Vec2{top.X + x, top.Y}, color)
}
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Offset | Vec2 | (0, 0) | Position of the shape in node space. |
| Is Trigger | bool | false | Detects overlaps and sends trigger events without pushing bodies apart. |
| Friction | float | 0.6 | Resistance to sliding along other shapes; 0 is ice. Two shapes use the square root of the product. ≥ 0 |
| Restitution | float | 0 | Bounciness: 0 stops on impact, 1 bounces back at the same speed. Two shapes use the larger value. ≥ 0 |
| Density | float | 1 | Mass per square unit; gives the body its mass when Mass Mode is auto. ≥ 0 |
| Points | []Vec2 | [4 items] | Corners in node space, 3 to 8, forming a convex shape; edit them in the Scene View. read-only in scripts |
From a script
Points is read-only in scripts; the shape is edited in the Inspector. Scripts change the surface instead.
package game
script Ice {
func Ready() {
poly := node.Get<PolygonCollider2D>()
poly.Friction = 0.02
poly.Restitution = 0
}
}
Script events
Scripts on a node with this component receive these events from the Physics 2D module.
OnCollisionEnter— Runs after the physics step in which this body started touching other.OnCollisionExit— Runs when the bodies stop touching, including when one of them is destroyed or disabled. Contact.Point is the last known point.OnCollisionStay— Runs after every later physics step while the bodies keep touching. It costs nothing when no script declares it.OnTriggerEnter— Runs when other's collider entered a trigger of this body, or this body entered other's trigger.OnTriggerExit— Runs when the overlap with a trigger ends.
Related guides
- Components These components make a node part of the simulation.
- Physics 2D Aego simulates 2D rigid bodies with its own solver.