Aego Русский

Edge Collider 2D

Polyline for level geometry. OneSided lets bodies pass from below.

component physics.EdgeCollider2D
On this page

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.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Edge
Transform
position[0, 3.7]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#6b7280ffsizeVec2[18, 0.12]
Edge Collider 2D
points[]Vec2[[-9, 0], [9, 0]]restitutionfloat0
Ball
Transform
position[0, 2.89]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000d00")tintColor#f59e0bffsizeVec2[1.6, 1.6]orderint1
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
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

NameTypeDefaultDescription
OffsetVec2(0, 0)

Position of the shape in node space.

Is Triggerboolfalse

Detects overlaps and sends trigger events without pushing bodies apart.

Frictionfloat0.6

Resistance to sliding along other shapes; 0 is ice. Two shapes use the square root of the product.

≥ 0
Restitutionfloat0

Bounciness: 0 stops on impact, 1 bounces back at the same speed. Two shapes use the larger value.

≥ 0
Densityfloat1

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
Loopboolfalse

Joins the last point to the first, for closed outlines; needs at least 3 points.

One Sidedboolfalse

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.