Skip to content

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.

  • 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.layer names what a body is, and arcade.hits names the layers it reports touching. On Contact’s with field 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.

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.

  1. Start a new file and save it as asteroid-bullet.blend. Add a small sphere named Bullet and give it Add Component ▸ Arcade ▸ Arcade Mover with the bullet’s tags from the table.

  2. Make an Asset-scope graph named bullet.hit: On Contact with with set to rock, wired to Destroy with Self in its Target. Set it as the bullet’s Graph in Object ▸ Simulacrum ▸ Behaviour. Press Build Cartridge.

  3. Save a new file as asteroid-rock.blend with one rock named Rock, an Arcade Mover with the rock’s tags.

  4. 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 method position → Spawn a shard at that position → a second Spawn → Destroy (Self) → Send Message on world:rock.destroyed, with a Constant of 20 in 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.

  5. 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.destroyed with a payload of 50. 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.

  1. Save a new file as asteroid-blaster.blend and rename its scene to Asteroid-Blaster.

  2. 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.

  3. 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:hold presses the button for as long as a finger is down.

  4. 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, add preload the same way: the three spawnables’ addresses separated by commas. The rules start only once all three are loaded.

  5. Add Empties with HUD Text for Score {score} Lives {lives} Wave {wave} Best {best} at the top, a control hint at the bottom, and GAME OVER at the centre while lost.

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.

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.

  1. A wave. On Load emits world:wave.next. On Message world:wave.next adds 1 to wave, then a For Loop from 1 to wave + 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.

  2. The count. On world:rock.spawned, add 1 to rocks. On world:rock.destroyed, take 1 from rocks and add the message’s Payload to score; when rocks reaches 0, emit world: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.

  3. Fire. On Input fire, while not lost: Call Component (Ship, position) → Spawn a bullet there → Call Component (Ship, forward, with 14 as 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 method setVelocity and that vector.

  4. The ship is hit. On Contact with target Ship and with rock: take a life and call reset on Ship. Out of lives, set lost, hide the ship with Set Enabled, and emit world:game.over.

  5. The best score. On world:game.over, keep the higher of score and best, as in tutorial 1.

  1. Press Build Cartridge. The game lists its three spawnables as files it depends on.

  2. Publish the four cartridges (Publish and share) so the game can reach the spawnables at their addresses.

  3. Open the game and press Space: a bullet leaves the ship’s nose, and a rock it hits breaks into two shards.

  • 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, forward and setVelocity to graphs.

Next: The trail builds a game from data tables, choices and drawings.