Aego Русский

Gameplay kit

The gameplay module adds the parts most 2D games rebuild by hand: a character controller, hit points, hitboxes and hurtboxes, kill zones, checkpoints with respawn, pickups and timed removal. They are components, so they are set up in the Inspector, saved with the scene and driven from scripts with a few calls.

Quick start: Create → Gameplay → Platformer Character gives a node with a kinematic Rigid Body 2D, a collider, Motion 2D, Health, Hurtbox 2D and Respawn. Give it a script that calls Move and Jump, add a floor and press Play.

In the interactive guide, walk with A/D or the arrow keys and jump with Space, W or Up.

Two complete games use the kit: aego new mygame --example platformer (stomping enemies with a foot hitbox, a pit with a kill zone, a checkpoint, a persisted respawn point and an Animator for the player's look, with a slash on a hit frame) and aego new mygame --example topdown (a sword swung towards the stick, the mouse or the walking direction, enemies whose State Machine switches between Patrol and Chase while their Animator shows it, a lunge by root motion, coins and lava). The launcher offers both under Examples.

Component Purpose
Motion 2D walks, jumps and slides a kinematic body: slopes, steps, moving platforms, top-down movement
Health hit points, team, invulnerability after a hit, death and revive
Hurtbox 2D area where hitboxes hurt a Health
Hitbox 2D area that damages hurtboxes, with knockback
Lifetime removes a node after some seconds
Kill Zone 2D kills or respawns what falls into it
Checkpoint 2D moves the respawn point
Respawn brings a node back to its respawn point
Pickup 2D fires Collected when a character touches it
State Machine named states with Enter, Exit, Fixed and Update hooks in the node's scripts

Everything runs during Play and in aego run, in the fixed step, and allocates nothing per step. Hurtboxes, hitboxes and zones are areas in their node's space, not physics colliders: they never push anything and need no collision layers.

Try it

Change the example parameters and compare the result. Reset restores the initial scene.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene7 nodes
Floor
Transform
position[0, 3]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[40, 1]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[40, 1]
Slope
Transform
position[9, 1.6]rotation-0.5236scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#6b7280fforiginVec2[0.5, 0.5]sizeVec2[6, 1]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[6, 1]
Step
Transform
position[-4, 2.4]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#6b7280fforiginVec2[0.5, 0.5]sizeVec2[3, 0.2]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[3, 0.2]
Wall
Transform
position[-12, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[1, 6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[1, 6]
Lift
Transform
position[15, 2.3]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#0ea5e9fforiginVec2[0.5, 0.5]sizeVec2[3, 0.4]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumkinematicmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepboolfalseinterpolatebooltruelayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0densityfloat1sizeVec2[3, 0.4]
Player
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint1tintColor#f59e0bfforiginVec2[0.5, 0.5]sizeVec2[0.6, 1]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumkinematicmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationbooltruebulletboolfalseallowSleepboolfalseinterpolatebooltruelayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0restitutionfloat0densityfloat1sizeVec2[0.6, 1]
Motion 2D
modeenumplatformerupDirectionVec2[0, -1]maxSpeedfloat6accelfloat60decelfloat50airControlfloat0.6gravityScalefloat1maxFallSpeedfloat20jumpHeightfloat2.2jumpSpeedfloat0jumpCutMultiplierfloat0.5coyoteTimefloat0.1jumpBufferfloat0.1maxSlopefloat45stepHeightfloat0.25snapToGroundfloat0.2safeMarginfloat0.02maxSlidesint4collisionMasklayer mask-1pushBodiesbooltruemovingPlatformsbooltrueplatformOnLeaveenumkeepfaceMovementboolfalsedashGravityboolfalse
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat36viewportRect[0, 0, 1, 1]maskint-1orderint0clearbooltrueclearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Virtual Camera 2D
priorityint0outputstring""zoomfloat0blendTimefloat0.5blendCurveCurve{ ease=inOutQuad }timeDomainenumunscaleduseBoundsboolfalseboundsRect[0, 0, 0, 0]snapToPixelsboolfalse
Camera Follow 2D
targetNodeRefnode("d6100000000000000000000000000006")deadzoneRect[0.4, 0.4, 0.2, 0.2]dampingVec2[5, 5]lookaheadVec2[0.2, 0]maxLookaheadVec2[2, 1]lookaheadSmoothingfloat3snapDistancefloat20
Scriptmain.aes
package demo

import "aego/input"

// Player walks with A/D or the arrows and jumps with Space, W or Up.
script Player {
    func Update(dt float) {
        m := node.Get<Motion2D>()
        x := 0.0
        if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
            x -= 1
        }
        if input.Down(input.KeyD) || input.Down(input.KeyRight) {
            x += 1
        }
        m.Move(x)
        if input.KeyPressed(input.KeySpace) || input.KeyPressed(input.KeyW) || input.KeyPressed(input.KeyUp) {
            m.Jump()
        }
        if input.KeyReleased(input.KeySpace) || input.KeyReleased(input.KeyW) || input.KeyReleased(input.KeyUp) {
            m.JumpReleased()
        }
    }
}

// Lift moves a kinematic platform up and down.
script Lift {
    @export var Travel Vec2 = Vec2{0, -3}
    @export var Period float = 4

    var t float
    var start Vec2

    func Ready() {
        start = node.Transform2D().Position
    }

    func FixedUpdate(dt float) {
        t += dt
        phase := t / Period
        k := phase - float(int(phase))
        if k > 0.5 {
            k = 1 - k
        }
        k *= 2
        body := node.Get<Body2D>()
        body.MoveTo(Vec2{start.X + Travel.X*k, start.Y + Travel.Y*k}, 0)
    }
}