README
¶
NSGo Game Racing 3D Template
A small 3D racing game built with NSGo and github.com/nsgo-dev/game: two laps of a closed circuit against two computer-driven rivals, starting from the back of the grid.
It shows:
- Raycast cars from
vehicle3don aphysics3dworld: suspension, tire grip, steering and brakes, with every car's tuning in one YAML file. - Lap and checkpoint counting with
vehicle3d.Race: a lap counts only when a car passes every checkpoint in order, so cutting the track does not pay. - A three-second countdown, a position and lap clock in a native HUD, and a results screen that ends in a win (first place) or a loss (any other place, or not finishing before both rivals do).
- Rivals that follow a racing line: pure-pursuit steering toward a point ahead on the line and a speed plan that brakes for each corner, scaled by each rival's pace.
- A ghost of your best flying lap, recorded with
vehicle3d.GhostRecorder, raced against on every lap after the first and saved between launches as the YAMLvehicle3d.EncodeGhostwrites. Lap 1 starts on the grid behind the line, so it is neither saved as the ghost nor raced against one; a one-lap race has no ghost. The ghost is kept only for the exact track it was driven on: editing anything indata/track.yamlretires it. - A scene drawn on a
gpu.Viewwithrender3d's lit PBR pipeline: the road, curbs, checkpoint posts and cars are meshes built in code, and the trackside crates are the placeholder pack'scrate.glbread withgltf. - Keyboard, gamepad and touch from one input map in
game.yaml, read withinput.Actionsandvehicle3d.Controls, and aninput.VirtualPadfor the on-screen stick and pedals. - Headless tests with
nsgotestthat play whole races with each kind of input and reach both a win and a loss.
Controls
| Keyboard | Gamepad | Touch | |
|---|---|---|---|
| Accelerate | Up or W | Right trigger or A | GAS |
| Brake, then reverse | Down or S | Left trigger or X | BRAKE |
| Steer | Left and Right, or A and D | Left stick or the D-pad | the stick, anywhere on the lower left |
| Handbrake | Space | B | |
| Back on the road | R | Y | R |
| Race again | Enter | Start | Race again |
Running and Testing
go tool nsgo dev # the desktop, with hot reload
go tool nsgo dev -target web # the browser
go tool nsgo dev -target ios_simulator
go tool nsgo dev -target android
go tool nsgo test ./... # the headless tests
go tool nsgo check -target macos,windows,linux,android,web
The game's settings live in game.yaml, its project file. Edit the name and identifier there before shipping it, then write them into 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
Layout
game.yaml: the project file, with the window and the input map: the actionsthrottle,brake,steerLeft,steerRight,handbrake,respawnandconfirm, and thesteeraxis over the keys and the left stick.data/track.yaml: the circuit: its centerline points, width, laps, checkpoints, starting grid and the rivals' names, colors, pace and lanes.ParseTrackintrack.goreads it and refuses unknown fields.data/car.yaml: the car's tuning, avehicle3d.Config.track.go: the track file's format.course.go: the track turned into geometry, samples along the centerline and the racing line's speed at each.race.go: the race itself, with no drawing: the physics world, the cars, the countdown, the laps, the standings, the results and the ghost.driver.go: the racing-line driver the rivals use.scene.go,meshes.goandrenderer.go: the meshes, the lights, and the GPU drawing.game.go: the root component: the GPU view, the HUD, the results screen, the touch controls, the chase camera and thegame.Loop.CREDITS.md: where every asset comes from and its license.*_test.go: the tests:game_test.goplays races through the app,race_test.gothrough the simulation alone, andtrack_test.gochecks the track format.
Where to change it
- A new circuit: edit
points,widthandstartindata/track.yaml, keeping every point within 300 m of the origin, where the ground is. The road, curbs, checkpoints, grid and racing line all follow the points;TestCourseGeometrychecks the result still makes sense. - Harder or easier rivals: raise or lower each rival's
pace, or add rivals (up to seven). More laps:laps. - A different car: edit
data/car.yaml.vehicle3d.ReferenceConfigdocuments each field; a heavier car needs stiffer springs. - Cars that collide with each other: add
layerCarto the chassis mask innewRace, inrace.go. They pass through each other by default so a crowded corner never wrecks the race. - Other controls: change the bindings in
game.yaml; the game reads only action and axis names. - Your own models: load a glTF file with
gltf.LoadFSinsceneMeshesand add its primitives as parts, as the crates are.
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
Click to show internal directories.
Click to hide internal directories.