Asteroid-Blaster
For creatorsAdd-on 2.2.2+
In this tutorial you build a ship that turns, thrusts and fires at drifting rocks. A big rock splits into two shards when you hit it, and every cleared wave brings a bigger one. Every bullet, rock and shard is created while the game runs and removed when it is done. This builds on tutorial 1, Brick breaker.
▶ Play the finished game: ← → turn, ↑ thrusts, Space fires. On a phone, your finger’s position turns the ship, holding a finger down thrusts, and a tap fires.
Three ideas
Section titled “Three ideas”- A spawnable is its own small cartridge. The bullet, the rock and the shard are each built in their own Blender file. The Spawn node places a copy of one while the game runs, and each copy has its own graph.
- Layers.
arcade.layernames what a body is, andarcade.hitsnames the layers it reports touching. On Contact’swithfield hears only one layer, so a rock reacts to a bullet and ignores the ship. - Destroy is final. Destroy removes a node for good, with its graph and its body. Set Enabled only hides one.
1. Build the three spawnables
Section titled “1. Build the three spawnables”Each spawnable is a file with one object. Give that object the tag asset.primary = 1 (Object ▸ Simulacrum ▸ Tags ▸ Add Tag): it marks the object the Spawn node hands back.
-
Start a new file and save it as
asteroid-bullet.blend. Add a small sphere namedBulletand give it Add Component ▸ Arcade ▸ Arcade Mover with the bullet’s tags from the table. -
Make an Asset-scope graph named
bullet.hit: On Contact withwithset torock, wired to Destroy with Self in its Target. Set it as the bullet’s Graph in Object ▸ Simulacrum ▸ Behaviour. Press Build Cartridge. -
Save a new file as
asteroid-rock.blendwith one rock namedRock, an Arcade Mover with the rock’s tags. -
Give the rock an Asset-scope graph named
rock.hit:- On Load → Send Message on
world:rock.spawned. The rules count rocks this way. - On Contact (
with:shot) → Call Component with Self as its Component and the methodposition→ Spawn a shard at that position → a second Spawn → Destroy (Self) → Send Message onworld:rock.destroyed, with a Constant of20in its Payload: the points. - The Spawn nodes’ Asset pin takes a Constant (string) holding the shard’s address,
/scenes/asteroid-shard/scene.osmx.
Press Build Cartridge.
- On Load → Send Message on
-
Save a copy as
asteroid-shard.blend. Make the rock smaller and its launch faster, and give it a graph that only reports itself: On Load →world:rock.spawned, and On Contact (with:shot) → Destroy (Self) →world:rock.destroyedwith a payload of50. Press Build Cartridge.
| Object | Component | Tags |
|---|---|---|
Bullet |
Arcade Mover | arcade.layer = shot, arcade.hits = rock, arcade.lifetime = 1.1 (it destroys itself after 1.1 s), arcade.wrap = -8.5,-14.5,8.5,0.5, asset.primary = 1 |
Rock |
Arcade Mover | arcade.layer = rock, arcade.launch = random (it sets off on a random heading), arcade.launchSpeed = 1.6, arcade.wrap = -8.5,-14.5,8.5,0.5, asset.primary = 1 |
| Shard | Arcade Mover | as the rock, with arcade.launchSpeed = 2.6 |
arcade.wrap is the field’s edges as min x, min z, max x, max z: a body leaving one edge comes back in at the other.
A spawnable’s address is its web path (World ▸ Simulacrum ▸ Cartridge ▸ Web path, which the build takes from the file name) followed by /scene.osmx.
2. Build the game file
Section titled “2. Build the game file”-
Save a new file as
asteroid-blaster.blendand rename its scene toAsteroid-Blaster. -
Model the ship, name it
Ship, and give it Arcade Mover with the ship’s tags below. It steers like a ship: an action turns it, another pushes it along its facing. -
In World ▸ Simulacrum ▸ Input, press Add Action three times:
turn=keys:ArrowLeft/KeyA,ArrowRight/KeyD ; touch:x,thrust=keys:ArrowUp/KeyW ; touch:hold,fire=keys:Space ; touch:tap.touch:holdpresses the button for as long as a finger is down. -
In World ▸ Simulacrum ▸ Camera, press Add Setting for each camera setting:
mode=fixed,at=0,21,-2.4,target=0,0,-7.2,fov=52. In Spawning, addpreloadthe same way: the three spawnables’ addresses separated by commas. The rules start only once all three are loaded. -
Add Empties with HUD Text for
Score {score} Lives {lives} Wave {wave} Best {best}at the top, a control hint at the bottom, andGAME OVERat the centre whilelost.
| Object | Component | Tags |
|---|---|---|
Ship |
Arcade Mover | arcade.turn = turn, arcade.turnSpeed = 220, arcade.thrust = thrust, arcade.thrustAccel = 10, arcade.drag = 0.5, arcade.maxSpeed = 9, arcade.wrap = -8.5,-14.5,8.5,0.5, arcade.layer = ship, arcade.hits = rock, arcade.grace = 2 |
arcade.grace = 2 keeps the ship safe for two seconds after it comes back. Without it, a ship reborn on top of a rock dies again at once.
3. Write the rules
Section titled “3. Write the rules”Make a Scene-scope graph named blaster.rules, set it as World ▸ Simulacrum ▸ Rules, and declare score, lives (3), wave, rocks and lost as Scene variables and best as a Persistent variable saved for the Player.
-
A wave. On Load emits
world:wave.next. On Messageworld:wave.nextadds 1 towave, then a For Loop from 1 towave+ 2 spawns a rock each time. Its position is a Vector of a Random Range x across the field, 0.2 and a Random Range z along the top edge. -
The count. On
world:rock.spawned, add 1 torocks. Onworld:rock.destroyed, take 1 fromrocksand add the message’s Payload toscore; whenrocksreaches 0, emitworld:wave.next. A big rock’s two shards announce themselves before the rock reports its own end, so the count never touches 0 in the middle of a split. -
Fire. On Input
fire, while notlost: Call Component (Ship,position) → Spawn a bullet there → Call Component (Ship,forward, with14as its Argument) gives the ship’s facing at 14 m/s → Call Component on the spawned bullet (the Spawn node’s Spawned pin) with the methodsetVelocityand that vector. -
The ship is hit. On Contact with
targetShipandwithrock: take a life and callresetonShip. Out of lives, setlost, hide the ship with Set Enabled, and emitworld:game.over. -
The best score. On
world:game.over, keep the higher ofscoreandbest, as in tutorial 1.
4. Build and play
Section titled “4. Build and play”-
Press Build Cartridge. The game lists its three spawnables as files it depends on.
-
Publish the four cartridges (Publish and share) so the game can reach the spawnables at their addresses.
-
Open the game and press Space: a bullet leaves the ship’s nose, and a rock it hits breaks into two shards.
What you learned
Section titled “What you learned”- A thing that appears during play is a small cartridge of its own, placed with Spawn and removed with Destroy.
- Layers decide who reports touching whom, with no text comparisons in the graph.
- Arcade movers also offer
position,forwardandsetVelocityto graphs.
Next: The trail builds a game from data tables, choices and drawings.