Aego Русский

Box Collider 2D

Box shape in node space.

component physics.BoxCollider2D
On this page

Try it

Box collider bounce

A box is launched toward the floor with gravity off. At Restitution 0 it stops when it hits.

Change Restitution from 0 to 1 to make the box bounce on the same contact. Reset restores the original collision.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Box
Transform
position[0, 3.19]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint1tintColor#f59e0bfforiginVec2[0.5, 0.5]sizeVec2[1.5, 1]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumdynamicmassModeenumautomassfloat0gravityScalefloat0linearDampingfloat0angularDampingfloat0fixedRotationbooltruebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[1.5, 1]
Floor
Transform
position[0, 4]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[18, 0.6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[18, 0.6]
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40viewportRect[0, 0, 1, 1]maskint-1orderint0clearbooltrueclearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

import "aego/physics"

// Begin just above the floor, moving down. Collider restitution changes the
// actual contact response; gravity is disabled so the stopped baseline holds.
script Impact {
    func Ready() {
        body := node.Get<Body2D>()
        body.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
SizeVec2(1, 1)

Width and height in units, before the node scale.

From a script

Grow the collider together with the sprite, for a power-up.

package player

script Grow {
    func Apply(factor float) {
        box := node.Get<BoxCollider2D>()
        box.Size = box.Size * factor
        sr := node.Get<SpriteRenderer>()
        sr.Size = sr.Size * factor
    }
}

Script events

Scripts on a node with this component receive these events from the Physics 2D module.