Aego Русский

Capsule Collider 2D

Capsule along the local X axis; Length is the full extent including the caps.

component physics.CapsuleCollider2D
On this page

Try it

Capsule collider bounce

The visible horizontal capsule moves toward the floor with gravity off. At Restitution 0 it stops on contact.

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

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene5 nodes
Capsule
Transform
position[0, 3.29]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")orderint1tintColor#f59e0bffsizeVec2[0.8, 0.8]
Left cap
Transform
position[-0.4, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000d00")orderint1tintColor#f59e0bffsizeVec2[0.8, 0.8]
Right cap
Transform
position[0.4, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000d00")orderint1tintColor#f59e0bffsizeVec2[0.8, 0.8]
Floor
Transform
position[0, 4]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")orderint0tintColor#4b5563ffsizeVec2[18, 0.6]
Box Collider 2D
sizeVec2[18, 0.6]
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

import "aego/physics"

// The visible capsule matches the collider's dimensions. It strikes the
// floor at a fixed speed so Restitution changes the real contact response.
script CapsuleImpact {
    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
Lengthfloat1

Full length along the local X axis, caps included.

≥ 0
Radiusfloat0.25

Radius of the caps and half the thickness.

≥ 0

From a script

Crouch by shortening the capsule.

package player

import "aego/input"

script Crouch {
    var Standing float = 1
    var Crouching float = 0.4

    func Update(dt float) {
        capsule := node.Get<CapsuleCollider2D>()
        capsule.Length = Standing
        if input.Held("Crouch") {
            capsule.Length = Crouching
        }
    }
}

Script events

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