action3d

command
v0.4.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Action Adventure

A third-person 3D action adventure built with NSGo and github.com/nsgo-dev/game. A knight crosses a walled courtyard, fights the guards, jumps onto a ledge for the key, and the key opens the gate to the shrine. Reaching the shrine wins; losing all health loses.

It shows:

  • An orbit camera (scene3d.OrbitController) that follows the hero, turns with the player and moves in front of walls between it and the hero, found by sweeping a physics3d sphere along the arm so the lens keeps clear of corners.
  • A capsule character controller per actor in a physics3d.World of static boxes, with walking, jumping onto a ledge and a door that leaves the world when it opens.
  • Run, jump, attack, flinch and fall animations on a rig of boxes, played by an anim3d.StateMachine whose locomotion state blends idle into run by speed (anim3d.BlendSpace1D), with conditional transitions and a hit clip event that lands each blow.
  • Enemies that chase the hero inside their sight and leash, wind up a slow swing the hero can interrupt, and walk home when the hero gets away.
  • A level that is a scene file: blocks, the spawn, enemies, the key, the door, the goal and the lamps are objects with components, and a connection in the scene, not Go code, makes picking up the key unlock the door.
  • render3d's lit PBR pipeline drawing every box from one cube mesh, lit by a moon, an ambient fill and the scene's lamps.
  • A pause that is always reachable: Escape or P, a controller's Start or the HUD's Pause button open a menu over the frozen level with Resume and Restart. Losing focus, the app going to the background or the active controller disconnecting pauses the same way, and resuming ignores the controls for half a second so a movement key still held from before the pause does not lurch the hero.
  • Keyboard and mouse, game controller and touch, all through one input.Actions bound from game.yaml, with on-screen sticks and buttons (input.TouchControls) placed inside the safe area from controls.touch.yaml (visible from the first frame on phones and on desktop once touched).
  • Headless tests that play the whole run to a win with a game controller and to a loss with the keyboard, drive the touch controls and draw the level on a software GPU.

Controls

Keyboard and mouse Game controller Touch
Move W A S D or the arrow keys Left stick or D-pad Drag on the left half
Turn the camera Q and E, or drag with the mouse Right stick or the shoulder buttons Drag on the right half
Jump Space A (south) Jump button
Attack J or Enter X (west) or the right trigger Attack button
Pause and resume Escape or P Start The Pause button in the HUD
Play again after the run ends R Start Play again button

Running and testing

go tool nsgo dev                 # the desktop, with hot reload
go tool nsgo dev -target web     # the browser
go tool nsgo test ./...          # the headless tests
go tool nsgo check -target macos,windows,linux,android,web

Debug the game's Go code with Delve (dlv on PATH):

go tool nsgo dev -target native -debug

Attach from VS Code with the Attach to game configuration in .vscode/launch.json, replacing 40000 with the port in Delve's API server listening at line, or from GoLand with a Go Remote configuration at the same host and port.

Layout

  • game.yaml — the project file: name, id, window, the input map (actions, axes and game controller sticks, including the pause and restart actions), the scene and data files to autoload, and export presets.
  • controls.touch.yaml — the on-screen touch layout (input.TouchControls): floating move and camera sticks, and Attack and Jump buttons anchored inside the safe area.
  • scenes/keep.scene.yaml — the level, a scene file the scene editor opens (go run github.com/nsgo-dev/game/cmd/game editor .). Each object's x, y (up) and posZ place it in meters, its scale sizes a box, and its components say what it is: block, spawn, enemy, key, door, goal or lamp. Objects sit at the top of their layer, not inside one another, and only the spawn is rotated, by rotY. The connections at the end wire the key's collected event to the door's unlock handler.
  • data/actors.yaml — the hero's and the enemies' tuning (health, speed, jump, reach, damage, swing speed, knockback and colors), the rig of boxes both share, and the animation clips in degrees and seconds. actors.go defines and checks its format.
  • level.go — the level's component types and how a scene becomes boxes, spawns and lamps.
  • game.go — the simulation: the physics world, hero and enemy rules, the key, the door and winning and losing. It knows nothing of devices or the GPU.
  • rig.go — turns the rig and clips into anim3d clips and a state machine per actor, and poses the boxes.
  • render.go — the camera, the lights and the GPU renderer.
  • view.go — the root component: the fixed-step game.Loop, input, the HUD with the Pause button, the pause menu and the touch controls.
  • project.go, main.go — embed the project and its files and start the app.
  • *_test.go — the playthroughs, input, rendering and file-format tests.

Where to change it

  • Move walls, add enemies or lamps, or build a new level in scenes/keep.scene.yaml; the tests check that it still loads, and the bot's route in game_test.go says how a run is won.
  • Tune the fight in data/actors.yaml: slower enemy swings (attackSpeed), more health or a longer reach change the difficulty without touching code.
  • Add an animation by adding a clip to data/actors.yaml and a state to newAnimator in rig.go.
  • Add a component type in levelComponents (level.go), such as a moving platform, and read it in buildLevel.
  • Replace the boxes with glTF models: install the cc0-adventurers library pack (go run github.com/nsgo-dev/game/cmd/game library install cc0-adventurers) for two CC0 rigged characters (knight.gltf, mage.gltf) sharing twelve clips (Attack, AttackHeavy, Block, Death, Defeat, Dodge, Hit, Idle, Jump, Run, Victory, Walk) and an adventurer.animgraph.yaml locomotion graph; verify with game check and game credits, add packs to the //go:embed directive in project.go, load with gltf.LoadFS and anim3d.LoadGraph, and draw skinned meshes with render3d.UploadMesh in renderer.draw.

After editing game.yaml, write the name and id it shares with nsgo.yaml and check the project:

go run github.com/nsgo-dev/game/cmd/game project sync
go run github.com/nsgo-dev/game/cmd/game project check

After moving or adding files, go run github.com/nsgo-dev/game/cmd/game index keeps game.index.yaml, the project's index of stable file IDs, up to date.

Git setup

Each clone enables the object-by-object scene merge driver once (.gitattributes names it, while Git keeps driver config local to .git/config):

go tool game merge -setup

Documentation

Overview

Command mygame is a third-person 3D action adventure built with NSGo and game.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL