Edge Collider 2D
Polyline for level geometry. OneSided lets bodies pass from below.
component physics.EdgeCollider2D
Try it
Bounce on an edge
The grey line marks a real edge collider. With gravity off and Restitution 0, the ball stops on contact.
Change the edge's Restitution from 0 to 1 to make the same impact bounce. Reset restores the original contact.
Scene3 nodes
Scriptmain.aes
package demo
import "aego/physics"
// The ball hits the visible edge at a fixed speed. Its zero restitution makes
// the edge's restitution determine whether this contact stops or bounces.
script EdgeImpact {
func Ready() {
node.Get<Body2D>().SetVelocity(Vec2{0, 15})
}
}
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 | [2 items] | Points of the line in node space, at least 2; edit them in the Scene View. read-only in scripts |
| Loop | bool | false | Joins the last point to the first, for closed outlines; needs at least 3 points. |
| One Sided | bool | false | Collides only from above, so bodies can jump through from below, as on a platform. |
From a script
Turn a platform into a one-way platform at run time.
package level
script OneWay {
var Enabled bool = true
func Ready() {
edge := node.Get<EdgeCollider2D>()
edge.OneSided = Enabled
}
}
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.