BreynGINE

My jungle adventure (on your phone)

This is the version for phones and tablets (Android), with the editor's touch interface. Making it on a computer? Go to the version for computers.
You're reading the tutorial in the phone's browser. In BreynGINE, ☰ > Help > Tutorials opens this same page and offers to copy the drawings and sounds it needs into your project; here you can also download them as a ZIP.

Chapter 1The Lost Temple

In this tutorial you'll make a third-person adventure in the style of Tomb Raider, in a world made of blocks: an explorer, a jungle, a Maya pyramid with its entrance shut… and an ancient mechanism to open it: push the stone onto the plate. The Golden Idol waits inside. Without writing a single line of code, and all of it on your phone.

"The Lost Temple", the game you are going to make. (The pictures of the phone show the editor in Spanish; the buttons are in the same places in English.)
"The Lost Temple", the game you are going to make. (The pictures of the phone show the editor in Spanish; the buttons are in the same places in English.)

Along the way you'll learn:

  • Block worlds (voxel style): placing and removing blocks with your finger, and generating a whole jungle with its pyramid in a moment.
  • Third person: an explorer with her camera behind her and animations to walk, jump and stand still.
  • Touch controls: a joystick and buttons on the screen, to play on a phone.
  • New BreynFlow pieces: Push Blocks, the event Pressure Plate and Shake Camera.
  • And in part two: variables that change the jump and the speed, a screen with life and ammo, weapons and bullets that get recycled (object pooling), fall damage and enemies that wake up with a message.

This is the version of the tutorial for the editor's touch interface, with pictures of the phone. If you don't know the bottom tabs yet (Scene, View, Inspector, Project, More), the workspace bar and the gestures, look at the chapter The editor on a phone of My first game: it also explains how BreynFlow rules work.

Tip: it's a long tutorial, and in 3D. It goes better on a big phone or a tablet, but any phone will do. And if you want to see it finished before you start, the Asset Store tab of the project manager has the template Jungle Adventure, Blocks: it's the game of this tutorial, ready to play and to look into its rules.

Chapter 2The project

1
In the project manager, tap New Project.
2
Name: The Lost Temple. Template: 3D (camera, light and sky).
3
Tap Create.

The editor opens in the 3D view with the scene main: a sky, the sun, a camera and a plane.

The explorer brings her own camera and the ground will be blocks, so delete what isn't needed: in the Scene tab, hold your finger on Main Camera and choose Delete. Do the same with Plane.

The drawings and the sounds

This tutorial comes with the drawing of the idol, the sounds of the game and a few more things for part two. With your project open, tap ☰ > Help > Tutorials > My jungle adventure (tutorial) and choose Copy and Open: BreynGINE copies them into the project and opens this page again. (You can also download them here (download the ZIP).)

☰ > Help > Tutorials, and "Copy and Open".☰ > Help > Tutorials, and "Copy and Open".
☰ > Help > Tutorials, and "Copy and Open".

The Project tab now has the folders sprites (the idol, the bullet, the ammo, the guardian and the weapons), weapons (the weapons in 3D) and sounds (the plate, the stone sliding, the temple door, the jump, the treasure, the sounds of the jungle, the shots...).

Chapter 3Moving around the 3D world

Before building, learn to look around. In the View tab, with the 3D view:

  • One finger taps to select, and drags the colored arrows to move what's selected.
  • Two fingers: pinch to zoom in or out, and drag to turn the camera around.
  • The axes at the top right (X, Y, Z) put the camera facing front, from above or from the side with one tap.
The 3D view on a phone, with the jungle you're going to generate.
The 3D view on a phone, with the jungle you're going to generate.
Tip: if you get lost, select an object in the Scene tab, go back to the View and tap ⋮ Perspective (top left of the view) > Focus Selection: the camera goes to the object.

Chapter 4The block world

Above the 3D view there's the Shapes button. Tap it and slide the menu all the way down: there's the section Blocks (Voxel).

Shapes: also block worlds, a block to push and a pressure plate.
Shapes: also block worlds, a block to push and a pressure plate.

Choose Block World. Blocks shows up in the Hierarchy and, in the More tab, its palette (the GridMap panel): grass, dirt, stone, mossy stone, carved stone, log, leaves, planks, sand, water, gold, tall grass and flowers.

The block palette, in the More tab. The row of tools at the top slides with your finger.
The block palette, in the More tab. The row of tools at the top slides with your finger.

Each block is 1 meter wide and has its picture on top, on the sides and below, like in construction games: grass is green on top and earth on the sides. The pictures are copied to the blocks folder of the project the first time.

Tip: blocks are already solid: the explorer will walk on them and bump into them. Plants and water are not: they can be walked through.

Chapter 5Generate the jungle

Placing thousands of blocks with your finger would take weeks. To start, let BreynGINE make the jungle: Shapes > Generate Jungle...

Size, seed and what to put.
Size, seed and what to put.
  • Size: how many blocks wide it is. Leave 48.
  • Seed: each number makes a different jungle (the same number, the same jungle). Leave 1, so everything ends up where the tutorial says.
  • Leave the four boxes checked: the ground with hills and ponds, the trees, the plants and the Maya pyramid.

Tap Generate.

A whole jungle, with mountains around it, trees with vines and the pyramid in a clearing.
A whole jungle, with mountains around it, trees with vines and the pyramid in a clearing.

The pyramid has four floors with carved bands, a great stairway to the south and a temple on top. Inside, it hides a tunnel and a treasure chamber. The entrance is at the foot of the stairway, facing south (towards +Z), and a sand path leads to it.

Tip: don't like it? ↶ (undo, at the top) takes it away. Try other seeds with the button Another: the pyramid is always in the same place, but the trees and hills change.

Chapter 6Building block by block

Now, with your finger: two columns at the entrance of the clearing, one on each side of the path.

1
With Blocks selected, go to the More tab and tap Carved Stone in the palette: the brush turns on.
2
Go back to the View. Bring the camera close (pinching) to the entrance of the clearing and tap the grass on the left of the path: the block appears there. Its position shows at the bottom left; the right one is (-3, 0, 11).
3
Tap on top of the new block: the next one is stacked on it. That's how On Blocks works (the button in the bar of the palette): the new block goes against the face of the block you tap.
4
In the palette, choose Gold and put a third block on top.
5
Do the same on the right of the path, at (4, 0, 11).
The second column, almost done.
The second column, almost done.

To erase, choose the eraser in the bar of the palette and tap the block you want to remove; the pencil goes back to the brush. The picker takes the block you tap, to keep painting with it. When you're done, tap the arrow in the bar of the palette (select): that way taps on the view select things again instead of painting.

Tip: if a block lands where you didn't want it, ↶ undoes it. And if you tap a plant or water, the new block replaces it.

Chapter 7The explorer

1
In the Scene tab, tap Main, the first line: it's the root of the scene, and what you create goes inside it. Tap the + at the top, slide the list down to 3D Game and choose Player (Third Person).
The third-person player, at the end of 3D Game.
The third-person player, at the end of 3D Game.
2
Name her Explorer: hold your finger on her in the Hierarchy and choose Rename.
3
Now, her position: 0.5, 0, 15, on the path, facing the pyramid. Go to the Inspector tab, tap Filter Properties, type position and you'll only see that property. Tap each number (x, y, z), type it and press Enter.
The Inspector's filter, and the explorer: made of blocks, with her braid and her backpack.The Inspector's filter, and the explorer: made of blocks, with her braid and her backpack.
The Inspector's filter, and the explorer: made of blocks, with her braid and her backpack.
Tip: the filter is your best friend on a phone: it works for any property of this tutorial (size, radius, energy...). When you're done, clear it with the X of the field to see everything again.

She comes with everything she needs:

  • Her Collider (a capsule) and her Body: boxes of colors, with the legs and arms hanging from their joints.
  • A Camera Pivot with a Camera Arm (a SpringArm3D) and the Camera at its tip: the camera stays behind her and, if a wall gets in between, it comes closer instead of going through it.
  • An AnimationPlayer with three animations: idle, walk and jump.
  • She's already in the group player.

Chapter 8Move, push and jump

With the Explorer selected, go to the Inspector tab, scroll to the bottom and tap Add Component > BreynFlow (Rules Without Code). Then go to the View and slide the workspace bar to BreynFlow.

The workspace bar, slid to Audio, BreynFlow and Sprites.
The workspace bar, slid to Audio, BreynFlow and Sprites.

Make these rules (with New Rule, + Condition and + Action; in the piece search you can type part of the name):

  • Move. WHEN: Every Frame. DO: Move with the Controls: tap the piece and, in its settings, set the style to Third Person, Speed 5 and, in Look, the animations idle, walk and jump. And another action: Push Blocks (it already comes with the group pushable).
The Move rule and the settings of Move with the Controls.The Move rule and the settings of Move with the Controls.
The Move rule and the settings of Move with the Controls.
  • Jump. WHEN: Key or Button ui_accept. IF: Is on the Floor. DO: Jump with force 6; Play Sound sounds/jump.wav (see the tip below).
  • Jungle sounds. WHEN: Scene Starts. DO: Play Music sounds/jungle.wav, repeating it whole.
The Jump rule, and Quick Load looking for the jump sound.The Jump rule, and Quick Load looking for the jump sound.
The Jump rule, and Quick Load looking for the jump sound.
Tip: to choose a sound, a texture or a picture, tap the little arrow of the field (in the settings of the piece or in the Inspector) and choose Quick Load...: a list opens with the files of the project that fit there. Type part of the name (jump, jungle...) and tap the file.

Tap the name of each rule ("Rule 1"...) to give it its own.

Chapter 9The touch controls

A phone has no keyboard and no mouse: the explorer needs a joystick to walk and a button to jump. With the Explorer selected, add one more rule:

  • Touch controls. WHEN: Scene Starts. DO: Touch Controls (type touch in the search box).

The action comes as "show the touch controls (joystick yes, buttons A = ui_accept)". Tap A = ui_accept and, in its settings, tap Buttons: each button is a pair, its text and the action it presses. Write Jump in New Key and ui_accept in New Value, tap Add Key/Value Pair and delete the A with its trash can.

The Touch controls rule, and its buttons (in part two you'll add the ones for the weapons).The Touch controls rule, and its buttons (in part two you'll add the ones for the weapons).
The Touch controls rule, and its buttons (in part two you'll add the ones for the weapons).

This is how it plays on a phone:

  • The joystick, on the left: it appears where you put your thumb and moves the explorer where the camera looks (Move with the Controls reads it as it is). She turns to where she walks.
  • Jump, at the bottom right, presses ui_accept: the Jump rule works as it is.
  • A finger anywhere else on the screen turns the camera around the explorer, like the mouse on a computer. Several fingers work at once: walk with one thumb and turn the camera with the other.
Tip: on a computer the touch controls don't show, and the game is played with the mouse, WASD and Space. The same game works for both.

Try it!

Save (💾) and tap ▶. Walk around the clearing, jump with Jump and climb the stairway of the pyramid jump by jump. To stop, tap ■ or close the game.

With the mist of the jungle, which we'll add at the end.
With the mist of the jungle, which we'll add at the end.

Push Blocks goes right after moving, in the same rule: if the explorer walks into a block of the group pushable, she pushes it.

Tip: a jump with force 6 goes almost 2 meters up: enough to climb one block easily. For longer jumps, raise it to 7 or 8.

Chapter 10The door, the plate and the stone

Now, the mechanism of the temple. The three things come from the Shapes button of the 3D view; first tap Main in the Scene tab so they're created in the scene (and not inside the Explorer).

The door: Shapes > Cube, named Door. In the Inspector, Size 3, 4, 1 and Position 0.5, 2, 1.5 (with the filter, type size and then position): it closes the entrance right under the carved lintel. In Look, the texture Stone.

The stone to push: Shapes > Pushable Block. Name it Block and set its Position to 8, 0, 13. It's a stone block of 2 × 2 × 2 meters, already in the group pushable.

The plate: Shapes > Pressure Plate. Name it Plate and set its Position to 8, 0, 9: two pushes away from the block, towards the pyramid.

From above: the door, the plate, the block and the explorer.
From above: the door, the plate, the block and the explorer.
Tip: the Block and the Plate are always placed on whole meters, like the blocks of the world, so they fit the grid.

Chapter 11The mechanism

Select the Block, add BreynFlow to it (Inspector > Add Component) and, in the BreynFlow view, make one rule:

  • Slide. WHEN: Message Received: pushed (it gets this message every time it's pushed). DO: Play Sound sounds/stone.wav.

And to the Plate, the rule that opens the temple:

  • Open the temple. WHEN: Pressure Plate. The piece says "anything steps on this object": it has two slots, and the first one is the one to change. Tap anything (in the settings it's the field With: what steps on it) and choose A group... > pushable. The second one, this object (the plate that is stepped on), stays as it is. It reads "the group "pushable" steps on this object": this way the plate doesn't react when the explorer steps on it, only to the stone.
  • DO: Play Sound plate.wav; another Play Sound door.wav; Shake Camera for 3 s with strength 0.3; Show Message "The entrance of the temple opens!" for 3 s; Move To: the Door, by an offset of (0, -3.9, 0) in 3 s. The door sinks slowly into the ground.
The rule of the Plate, on a phone.
The rule of the Plate, on a phone.

How Push Blocks works: when the explorer walks into the stone for a moment, the stone slides its own size (2 meters), if there's room. If there's a wall, a tree or another block in the way, it doesn't move. And the plate sinks a little while something is on it.

Tip: the Pressure Plate event can also fire when something steps off: with it you can close the door again if the stone is taken away, for harder puzzles.

Chapter 12The treasure

1
In the Scene tab, tap Main, then + > Pickup (3D). Name it Idol and set its Position to 0.5, 1, -5.5: on the golden pedestal of the treasure chamber.
2
Unfold the Idol in the Hierarchy (the little arrow on its left). Tap its Drawing and, in the Inspector, give it the texture sprites/idol.png (little arrow of the Texture field > Quick Load... > idol) and Position y = 0.5. Then tap its Collider: in the Inspector, in Shape, tap SphereShape3D to open it and set Radius to 0.9. So it can be picked up from the edge of the pedestal.
3
Tap the Idol again in the Hierarchy (not its Collider: the BreynFlow goes on the Idol). Add BreynFlow to it with the rule Take the treasure: WHEN: Collision (it already says "touches the group player"). DO: Play Sound treasure.wav; Show Message "You found the Golden Idol!" for 4 s; Destroy this object.

The torches: tap Main and + > Point Light, named Torch, at 0.5, 3.5, -5.5. In the Inspector: orange Color (tap the color and set 255, 170, 80), Energy 2, Range 7 and Shadow off (the shadows of point lights are costly, and they aren't needed here). Duplicate it (hold your finger > Duplicate): Torch 2, at 0.5, 3, 0, for the tunnel.

The treasure chamber: the idol on its pedestal, with a gold block in each corner.
The treasure chamber: the idol on its pedestal, with a gold block in each corner.

Chapter 13The mist of the jungle

The final touch: mist. In the Hierarchy, tap WorldEnvironment; in the Inspector, tap its Environment to open it and, in Fog:

  • Enabled: on.
  • Light Color: a very light green (158, 189, 158).
  • Density: 0.008.

The trees in the distance fade into the haze, and the clearing of the pyramid looks more hidden.

Chapter 14Let's play!

Save (💾) and tap ▶.

1
Walk to the stone (on the right of the entrance) and go around it until you're behind it, on the side of the path.
2
Push towards the pyramid: each push slides it 2 meters. With two, it reaches the plate.
Pushing the stone.
Pushing the stone.
3
Click! The ground shakes and the temple door sinks.
The entrance of the temple opens.
The entrance of the temple opens.
4
Go through the tunnel to the treasure chamber and take the Golden Idol.
The tunnel, with the idol at the end.
The tunnel, with the idol at the end.

While you play, the BreynFlow view makes each rule blink when it runs (on a phone the game covers the editor: close it with ■ and look at the counter of each rule).

Chapter 15Part two: the three idols

The Lost Temple works. Now let's turn it into a real adventure: three idols instead of one (and the power they give), a screen with life and ammo, damage from high falls, two weapons with bullets that get recycled, ammo pouches and two stone guardians that wake up when the temple opens.

Everything you need was already copied at the start: in sprites, the bullet, the ammo pouch, the guardian, the pistol and the shotgun; in weapons, the pistol and the shotgun in 3D; and in sounds, the shot, the shotgun, the weapon switch, pickup, hurt, the growl, the crumble, the fall and the power of the idols.

Variables to run and jump

For the idols to make the explorer faster and springier, her speed and her jump must live in variables, not in fixed numbers. Select the Explorer and, in her rules:

1
Rename the rule Jungle sounds to Start (tap its name) and add three Change Variable actions to it: speed (of the object) set to 5; jump (of the object) set to 6; and idols (global) set to 0. The first two belong to the explorer; the idol count is global so everyone can read it.
2
In Move, open the settings of Move with the Controls (tap the piece, or its ⋮ menu > Edit All Settings) and set Speed Source: Variable of the Object, and Speed Variable: speed.
3
In Jump, the same with the Jump action: Force Source: Variable of the Object, and Force Variable: jump.
The Start rule, with its variables.
The Start rule, with its variables.

The sentences change to "speed speed" and "force jump". The game plays the same as before, but now any rule can change those numbers while playing.

The idols count

Select the Idol and, in its rule Take the treasure, add a Change Variable: idols (global) add 1. It goes at the end: move it up to the second place with its ⋮ menu > Move Up. And change the message to "Golden idol {idols} of 3!", for 3 s: between braces, the message shows the value of the variable, so each idol says which one it is.

Now the other two. Hold your finger on the Idol in the Hierarchy and choose Duplicate: you get Idol 2, with the same rules. Set its Position to 0.5, 8, -5.5: inside the temple at the top, reached by the stairway.

The second idol, in the temple at the top.
The second idol, in the temple at the top.

The third goes even higher. Select Blocks, choose Gold in the palette (More tab) and paint a gold block on the very top of the pyramid, on the cap of the temple roof (at cell 0, 13, -6). Then duplicate the Idol again: Idol 3, at 0.5, 14, -5.5, on the gold.

The gold block on the cap of the pyramid, and the third idol on the summit.The gold block on the cap of the pyramid, and the third idol on the summit.
The gold block on the cap of the pyramid, and the third idol on the summit.

The power of the idols

The summit can't be reached with a jump of force 6: the temple wall is 3 meters high. The first two idols will give the explorer the power to climb. Select the Explorer and make two rules:

  • The power of the idols. WHEN: Variable Changes: idols (global). IF: Compare Variable: idols (global) is equal to 2. DO: Play Sound power.wav; Show Message "You feel the power of the idols! You jump higher and run faster." for 4 s; Change Variable jump (of the object) set to 9.5; Change Variable speed (of the object) set to 7; and a Particle Burst of 60 particles, size 1.5, for 1 s, at this object.
  • The three idols. WHEN: Variable Changes idols (global). IF: idols is equal to 3. DO: Play Sound treasure.wav; Show Message "You gathered the three idols! The Lost Temple is yours." for 6 s.
The power of the idols: only when the count reaches 2.
The power of the idols: only when the count reaches 2.

It doesn't matter in which order the first two are taken: as soon as the count reaches 2, the jump goes from 6 to 9.5 (almost 5 meters) and you can climb from the temple yard to its wall, from there to the roof and from there to the gold on the summit.

Tip: Variable Changes fires every time the variable changes, in any object. That's why the rule lives in the Explorer even though the idol is the one adding: what matters is the variable, not who touches it.

Chapter 16Life and the screen

Let's put life and ammo on the screen. First, two settings so it looks right on any screen. Open ☰ > Project > Project Settings:

  • Type stretch in the search box, tap Window and set Stretch > Mode to canvas_items: the screen grows with the window.
  • Type texture filter, tap Textures (in Rendering) and set Default Texture Filter to Nearest: pixels look sharp.

Go to the 2D view (in the workspace bar): the blue rectangle is the screen, 1152 × 648. Tap Main in the Hierarchy and, with + (section UI), add four things:

  • Text named Life: with the text LIFE: 100, font size 28 (Theme Overrides > Font Sizes), at Position 24, 596 (bottom left).
  • Text named Ammo: BULLETS: 12 SHELLS: 4, size 28, Position 580, 596.
  • Image named Pistol: sprites/pistol.png in its Texture, Expand Mode set to Ignore Size and, in Layout > Transform, Size 96, 52 and Position 1032, 584 (bottom right).
  • Image named Shotgun: sprites/shotgun.png, Ignore Size, Size 128, 48, Position 1008, 588. Hide it with the eye in the Hierarchy: you start with the pistol.
The screen, at the bottom: life, ammo and the weapon.
The screen, at the bottom: life, ammo and the weapon.
Tip: on a phone, the touch controls show on top of the game's screen: the joystick at the bottom left and the buttons at the bottom right, covering a bit of the life and the weapon. If it bothers you, move the texts and pictures up (for example, to 24 instead of 596) or make the controls smaller with size in the settings of Touch Controls.

The rules of the screen

Add BreynFlow to the Life text with these rules:

  • Start. WHEN: Scene Starts. DO: four Change Variable, all global: life set to 100, bullets set to 12, shells set to 4 and weapon set to "pistol" (type the word, no quotes).
  • Show the life. WHEN: Variable Changes: life (global). DO: Change Text of this object to "LIFE: {life}".
  • Show the ammo. WHEN: Variable Changes: bullets (global). DO: Change Text of the object Ammo to "BULLETS: {bullets} SHELLS: {shells}".
  • Show the shells: the same, but WHEN shells changes (duplicate the previous one with its ⋮ menu > Duplicate Rule and change only the variable).
  • Show the weapon. WHEN: Variable Changes: weapon (global). DO: If / Otherwise. Inside, the condition Compare Variable: weapon (global) is equal to "pistol". In then: Show or Hide Pistol (show) and Show or Hide Shotgun (hide). In otherwise: the other way round.
Tip: a text between braces, like {life}, is replaced by the value of the variable when shown. It works in Change Text and in Show Message.

Falling from high

A tall pyramid and a 5-meter jump call for a little care. Select the Explorer and add:

  • Fall. WHEN: Lands or Hits a Wall (it comes as "this object lands"). IF: Compare Variable: fall_height (of the object) is greater than 3.5. DO: Change Variable life (global) subtract 20; Play Sound fall.wav; Shake Camera 0.5 s with strength 0.2; Blink this object for 1 s.
  • Die. WHEN: Variable Changes: life (global). IF: life (global) is less or equal to 0. DO: Show Message "You fell in the Lost Temple..." for 2 s; Fade Screen to the color in 1.5 s; Restart Scene.

Every time a character lands, BreynFlow writes in its variable fall_height how many meters below the place where it left the floor it landed: a jump on flat ground is 0, however high; going down a step, 1; falling from the temple roof to the yard, 4. The fade takes 1.5 s to cover the screen, and then the scene starts again: the Start rule of Life sets the life back to 100.

Chapter 17The weapons

The bullet

First, the projectile. It's a small object with its own rules, which we'll save as a prefab (a scene of its own) so the explorer can throw copies.

1
Tap Main and add + > Pickup (3D). Name it Bullet and put it in front of the explorer, at 0.5, 1.2, 13.5, to see it well.
2
Give its Drawing the texture sprites/bullet.png and Position 0, 0, 0. Give its Collider Position 0, 0, 0 and, in its SphereShape3D, Radius 0.15: a little ball the size of the bullet.
3
Tap the Bullet and add BreynFlow to it with two rules:
  • Hit. WHEN: Collision: tap the group "player" and change it to the group enemies. DO: Send Message "hurt" to the other object (the field To: what it touched); Particle Burst of 16 particles of orange at the other object; Destroy this object.
  • Crash. WHEN: Collision, but this time clear the group (in the settings, the field With empty: "touches anything"). IF: Is in Group: the other object is in the group player... and in the ⋮ menu of the condition check Invert (NOT): the bullet is destroyed when it touches anything but the explorer. DO: Destroy this object.
The bullet, in front of the explorer.
The bullet, in front of the explorer.
4
Now turn it into a prefab: hold your finger on the Bullet in the Hierarchy and choose Save Branch as Scene... (at the end of the menu). Save it as bullet.tscn. Then delete it from Main (hold your finger > Delete): in the game there are no bullets until someone shoots.
Holding your finger on an object: Rename, Duplicate, Save Branch as Scene...
Holding your finger on an object: Rename, Duplicate, Save Branch as Scene...

The action to switch weapons

Input actions are defined in ☰ > Project > Project Settings > Input Map. A new project already comes with jump, shoot, interact and pause. Add one: type switch_weapon in Add New Action and tap Add.

The Input Map, filtered by the name of the action: the action and its Q key.
The Input Map, filtered by the name of the action: the action and its Q key.

On a phone, a touch button will press it, so it doesn't need a key. If you're also going to play on a computer, give it the Q key: tap the + of its row, type Q in Filter Inputs, choose the Q in Keyboard Keys and tap OK.

The weapons in her hand

The weapons folder has two models made of boxes: pistol.tscn and shotgun.tscn. In the Hierarchy, unfold the Explorer and her Body. Hold your finger on Right Arm, choose Instantiate Child Scene... and pick weapons/pistol.tscn: it goes inside the arm. Set its Position to 0, -0.8, -0.05: now she holds it. Do the same with shotgun.tscn, with Position 0, -1.05, -0.05, and hide it with the eye: she starts with the pistol.

The pistol, in the explorer's right hand.
The pistol, in the explorer's right hand.

The origin of each weapon (the point you move with its Position) is at the muzzle: that's where the bullets will come out. And since the weapon is inside the arm, it moves with it: it swings when she walks, and rises with the arm when she aims.

Aiming

First, the camera over the shoulder. In the Hierarchy, unfold the Explorer's Camera Pivot, tap the Camera Arm and set its Position to 0.9, 0, 0: the camera moves to the explorer's right shoulder. Shots go where the center of the screen points, so now you can see where they go.

Now select the Explorer and add two rules:

  • Aim. WHEN: Key or Button: mouse_right is pressed. DO: Aim (in Characters and Physics): it comes as "this object starts aiming".
  • Stop aiming. WHEN: Key or Button: mouse_right is released. DO: Aim, changing "starts aiming" to stops aiming.

mouse_right is the right mouse button, and on a phone it will be the Aim touch button. While it's held, the explorer turns to where the camera looks and raises her arm with the weapon towards the center of the screen; the camera comes closer over her shoulder, a crosshair shows in the middle and she walks slower.

Shooting

Select the Explorer and add three more rules:

  • Switch weapon. WHEN: Key or Button: switch_weapon is pressed. DO: Play Sound switch.wav; If / Otherwise with the condition weapon (global) is equal to "pistol"; in then: Change Variable weapon set to "shotgun", Show or Hide Body/Right Arm/Pistol (hide) and Show or Hide Body/Right Arm/Shotgun (show); in otherwise: weapon set to "pistol" and the two weapons the other way round.
  • Shoot the pistol. WHEN: Key or Button: mouse_left is pressed. IF: weapon (global) is equal to "pistol", and bullets (global) is greater than 0. DO: Aim with aims briefly (0.4 s: if you shoot without aiming, she raises the weapon for the shot); Throw (Projectile): in the settings, Scene bullet.tscn, From the object Body/Right Arm/Pistol, Direction where the camera looks, Speed 25; Change Variable bullets subtract 1; Play Sound shot.wav.
  • Shoot the shotgun. WHEN: mouse_left is pressed. IF: weapon is equal to "shotgun", and shells (global) is greater than 0. DO: Aim with aims briefly; three Throw (Projectile) like the pistol's, but From Body/Right Arm/Shotgun and with Spread 12 degrees (a fan of pellets); Change Variable shells subtract 1; Play Sound shotgun.wav; Shake Camera 0.2 s with strength 0.15.
Tip: in a rule with several equal actions, set up the first one and then use its ⋮ menu > Duplicate. And to make the shotgun rule, duplicate the whole pistol rule (⋮ menu of the rule > Duplicate Rule) and change what's needed.

Bullets get recycled: when one leaves the screen or is destroyed, it goes back to a reserve (an object pool) and the next shot reuses it instead of creating another. With hundreds of shots, the game doesn't choke creating and deleting objects. It's the Reuse setting of Throw, which comes on.

The weapon buttons

You still can't shoot on a phone. Select the Explorer, go to her Touch controls rule, tap the buttons and add three more pairs, as you did with Jump: Shoot = mouse_left, Aim = mouse_right and Weapon = switch_weapon.

The touch controls: the joystick on the left and a button for each action.
The touch controls: the joystick on the left and a button for each action.

The weapon rules don't change: Shoot and Aim press the mouse buttons, and Weapon presses switch_weapon. While you hold Aim, she aims; when you let go, she stops. And touching the screen away from the buttons doesn't shoot: it only turns the camera.

Ammo

Bullets run out. Tap Main and add + > Pickup (3D), named Pouch, at -4, 0, 12, with the texture sprites/ammo.png in its Drawing. Its rule:

  • Pick up. WHEN: Collision (touches the group player). DO: Change Variable bullets (global) add 12; shells (global) add 4; Play Sound pickup.wav; Destroy this object.
An ammo pouch.
An ammo pouch.

Duplicate it twice: Pouch 2 at 5, 0, 16 (by the path) and Pouch 3 at 0.5, 0, -3.5 (inside the treasure chamber, right out of the tunnel: you're going to need it).

Chapter 18The guardians of the temple

Inside the treasure chamber, two stone jaguars wait for someone to open the door.

1
Tap Main and add + > Enemy (3D). Name it Guardian, put it at -2, 0, -8 (at the back of the chamber, left of the pedestal) and give its Drawing the texture sprites/guardian.png. It's already in the group enemies.
A stone guardian.
A stone guardian.
2
Add BreynFlow to it with six rules:
  • Start. WHEN: Scene Starts. DO: Change Variable life (of the object) set to 100; awake (of the object) set to 0.
  • Wake up. WHEN: Message Received: wake_up. DO: awake set to 1; Play Sound growl.wav.
  • Chase. WHEN: Every Frame. IF: awake (of the object) is equal to 1. DO: Move Towards (Follow): towards the Explorer, speed 3.5, and in the settings Stop Distance 1.2.
  • Bite. WHEN: Time Passes: every 1 s. IF: awake is equal to 1, and Distance from this object to the Explorer less than 1.8. DO: Change Variable life (global: the explorer's) subtract 15; Play Sound hurt.wav; Blink the Explorer 0.5 s; Shake Camera 0.3 s with strength 0.25.
  • Hurt. WHEN: Message Received: hurt (the one the bullet sends). DO: life (of the object) subtract 34; Blink this object 0.2 s.
  • Defeated. WHEN: Variable Changes: life (of the object). IF: life (of the object) is less or equal to 0. DO: Play Sound crumble.wav; Particle Burst of 40 gray particles, size 1.5; Destroy this object.
The Bite rule: only awake, and only up close.
The Bite rule: only awake, and only up close.

Notice the two lives: the life of the object is the guardian's (each one has its own, even though they share rules) and the global life is the explorer's. Three pistol bullets (34 × 3) or a good shotgun blast up close finish a guardian.

3
Duplicate the Guardian: Guardian 2, at 3, 0, -8, on the other side.
The two guardians, at the back of the chamber, on both sides of the idol.
The two guardians, at the back of the chamber, on both sides of the idol.
4
They still need waking. Select the Plate and, at the end of its rule Open the temple, add Send Message "wake_up" to the group enemies: as soon as the stone presses the plate, both growl and come for you.
Tip: messages are how objects talk to each other without knowing each other: the plate doesn't know how many guardians there are, nor does the bullet know whom it hit. To make a third guardian you only need to duplicate one.

Chapter 19Let's play! (part two)

Save (💾) and tap ▶. The screen says LIFE: 100 and BULLETS: 12, with the pistol.

1
Try the shots in the clearing: Shoot for the pistol, Weapon and Shoot for the shotgun (the camera shakes and three pellets fly). Hold Aim: the camera goes over her shoulder and the crosshair shows; turn the camera with your other finger to aim. Take the pouch on the left.
Aiming with the shotgun: a fan of pellets.
Aiming with the shotgun: a fan of pellets.
2
Climb the stairway (along one side, since the tunnel is in the middle) to the temple at the top and take the second idol... or leave it for later: the order doesn't matter.
3
Push the stone onto the plate. When the door opens, you'll hear two growls from inside.
4
Go in carefully: the guardians come to meet you through the tunnel. Shoot while you back off; with the shotgun, up close, they fall sooner. If they bite you, the screen shakes and the life drops 15 at a time.
The guardians, in the tunnel.
The guardians, in the tunnel.
5
Take the idol from the pedestal (and the ammo pouch). With two idols, the power comes: the message, the particles and a jump that goes almost 5 meters up.
The power of the idols!
The power of the idols!
6
Go back to the temple at the top, jump from the yard to the wall, from the wall to the roof and from the roof to the gold: the third idol is yours.
The summit of the pyramid, with the third idol.
The summit of the pyramid, with the third idol.
7
To get down, better the way you came up: if you drop from the roof to the temple yard (4 meters, or 6 from the gold), the fall costs you 20 life.

If the life reaches 0, the screen fades to black and the adventure starts again.

Tip: to play it outside the editor, install it on your phone as an app: ☰ > Project > Tools > Generate APK (Android)..., as in the chapter Play it and share it of My first game.

Chapter 20What now?

You have your own adventure! Some ideas to keep going:

  • A two-plate puzzle: two stones, two plates and a variable that counts how many are pressed; the door only opens with both.
  • Traps: a hidden plate in the tunnel that, when the explorer steps on it, drops a block or restarts the scene.
  • Guardians in the jungle: duplicate a Guardian, put it among the trees and swap its Wake up rule for a Distance to the explorer: it sleeps on patrol until you come close.
  • Another weapon: a bow with Throw (Projectile) at a lower speed and an arrow prefab that hurts more.
  • Score: a global variable that goes up with each defeated guardian and shows on the screen.
  • Build: a bridge of planks over a pond, a tree house... with the palette and On Blocks.
  • Another jungle: Shapes > Generate Jungle with another seed or bigger (without the pyramid, if you've already placed your things).
Tip: in View as Code (above the rules), BreynFlow shows you what they would look like in C#: the third-person camera, pushing blocks, the pressure plate, throwing bullets with their pool and the height of falls, from the inside.

← All the tutorials