BreynGINE

My 3D shooter (tutorial)

You're reading the tutorial on the web. In the editor on a computer it's in Help > Tutorials, next to your project. The links that copy drawings and sounds into your project in the editor download them as a ZIP here; on a phone, BreynGINE offers to copy them when you open the tutorial.

Chapter 1Infernal Base

In this tutorial you'll make a first-person shooter in the style of the 90s classics, like Doom: the corridors of a base, demons that chase you, a pistol, medkits, ammo, a red key and a door that only opens with it. Without writing a single line of code.

"Infernal Base", the game you are going to make.
"Infernal Base", the game you are going to make.

Along the way you'll learn:

  • Shapes: building the level inside the editor itself, with floors, walls, stairs and textures, and opening doors in the walls.
  • Lights: setting the mood with colored lights.
  • 3D game objects: the first-person player, the enemies and the pickups, ready to use.
  • BreynFlow in 3D: moving with the mouse and WASD, shooting, chasing, biting, picking things up and opening doors.
Tip: if you haven't done the welcome tutorial yet, have a look at it first: it explains how BreynFlow rules work. Here we'll go a bit faster.
Tip: want to see it finished before you start? In the Asset Store tab of the Project Manager, download the template 3D Shooter: it's the game of this tutorial, ready to play and to look into its rules.

Whenever you're ready, press Next.

Chapter 2The project

1
In the project manager, press Create.
2
Name: Infernal Base. Template: 3D (camera, light and sky).
3
Press Create.

The editor opens on the 3D tab with the scene main: a sky, a light (the sun), a camera and a plane.

We'll build the level with shapes, and the player brings its own camera, so delete what we don't need: in the Hierarchy, click Main Camera, then Ctrl+click Plane, and press Delete.

The drawings and the sounds

So you don't have to draw everything, this tutorial comes with the game's drawings and sounds: copy the drawings and sounds to the project (download the ZIP).

Two folders appear in the Project panel: sprites (the demon, the gun, the muzzle flash, the medkit, the ammo and the key) and sounds (the shot, the pain, the death, the hurt, the pickup and the door).

Tip: when you finish, try swapping them for your own: the drawings open in the Sprites tab and the sounds in Audio.

Chapter 3The floor

The level has three rooms in a row: the starting room, the demons' room and the final room, with the exit. It's 12 meters wide and 30 long.

At the top of the 3D view there's the Shapes button. Open it:

Shapes: cubes, spheres, ramps, stairs, floors, walls... and the tools to combine them.
Shapes: cubes, spheres, ramps, stairs, floors, walls... and the tools to combine them.
1
Choose Floor. A 10 × 10 meter slab appears where the view is looking.
2
Press F2 (or double-click it in the Hierarchy) and call it Floor.
3
In the Inspector: Size = 12, 0.2, 30. And further down, in Transform > Position: 0, -0.1, -9.
4
In Look (right below Size), click the Stone texture.
The stone floor. In Look you choose the color and the texture.
The stone floor. In Look you choose the color and the texture.

Textures are measured in meters: however much you stretch a shape, they never get distorted, and they continue from one shape to the next. The first time you use one, it's copied to the project's textures folder.

Tip: to move around the 3D view: right click + WASD to fly, the wheel to get closer, Alt + click to orbit and F to focus the selection.

Chapter 4The walls

1
Shapes > Wall. Call it West Wall. In Look, choose Tech Panel. Size: 0.25, 3, 30. Position: -6, 1.5, -9.
2
With it selected, press Ctrl+D to duplicate it. Call the copy East Wall and set its Position x to 6.
3
Duplicate again: South Wall, with Size 12, 3, 0.25 and Position 0, 1.5, 6.
4
Three more copies of the south wall, changing only their Position z:
  • North Wall: z = -24.
  • Middle Wall: z = -6 (between the first and the second room).
  • Door Wall: z = -18 (between the second room and the final one).
The six walls, seen from above.
The six walls, seen from above.
Tip: copies made with Ctrl+D share their texture. If you change the color or the texture of one of them in Look, only that one changes.

Chapter 5Doors in the walls

Right now you can't go from one room to another. Let's cut an opening in the two middle walls with the Cut a Hole tool: one shape "bites" another.

1
Shapes > Cube. Call it Hole. Size: 2.4, 2.8, 1. Position: 0, 1.3, -6. It goes through the Middle Wall, and its bottom goes a little into the floor: that way the hole leaves no ledge to trip over.
2
In the Hierarchy, click Middle Wall and then Ctrl+click Hole. The order matters: first the shape that stays, then the one that makes the hole.
3
Shapes > Cut a Hole.
A doorway! The Hole is now inside the Middle Wall: if you move it, the opening moves.
A doorway! The Hole is now inside the Middle Wall: if you move it, the opening moves.

Do the same with the Door Wall: another cube, Door Hole, the same but at z = -18.

Tip: with Join you can merge several shapes into one, and Separate undoes the join or the hole. Everything can be undone with Ctrl+Z.

Chapter 6Ceiling, stairs and a platform

The ceiling: Shapes > Floor, called Ceiling, with Size 12, 0.2, 30, Position 0, 3.1, -9 and the Ceiling texture. Now the inside can't be seen from above: click the Ceiling's eye in the Hierarchy to hide it while you build (and show it again when you finish).

The stairs: in the second room, some stairs go up to a platform where the key will be.

1
Shapes > Stairs. Position: 4.25, 0.75, -9.5. Texture: Metal. They go up towards the back.
2
Shapes > Cube, called Platform. Size: 3.5, 1.5, 4. Position: 4.25, 0.75, -12.75. Texture: Metal.
The stairs and the platform, in the second room.
The stairs and the platform, in the second room.
Tip: stairs and ramps have handles (the red dots) to resize them in the view, and in the Inspector you can choose how many steps they have.

Chapter 7The lights

With the ceiling on, it's dark inside: the sun doesn't get in. Good: we'll set the mood with lights.

1
In the Hierarchy, select Main, press + and choose Light > Point Light. Position: 0, 2.6, 0. In the Inspector: Light > Energy = 1.5 and Omni > Range = 10. It's the light of the first room.
2
Duplicate it (Ctrl+D) for the second room: Position z = -12, Range = 12 and a red Color (like 255, 90, 60): the demons' room.
3
Another copy for the final room: z = -21, green.
The demons' room, with its red light.
The demons' room, with its red light.
Tip: to see the inside while you work, show the Ceiling and fly the view inside (right click + WASD).

Chapter 8The player

1
Select Main, press + and, in the 3D Game section, choose Player (First Person).
The objects for 3D games: the player, the enemy and the pickup.
The objects for 3D games: the player, the enemy and the pickup.

It comes with its body, a capsule-shaped collider and a Camera at eye level: what the player sees. It's already in the group player.

2
Set its Position to 0, 0, 3: in the first room, facing the doors.
3
Add BreynFlow to it (Add Component) and make the rule Move:
  • WHEN: Every Frame.
  • DO: Move with the Controls. Click platformer and, in the card, choose the first person style and Speed 5 (in 3D it's in meters per second).

Try it!

Save (Ctrl+S) and press ▶. Click the game: the mouse looks around and WASD (or the arrows) walks. Go through the doorways and up to the platform. Esc frees the mouse; a click catches it again.

Walking around the base.
Walking around the base.
Tip: does the view turn too fast or too slow? In the card of Move with the Controls, change the Mouse Sensitivity.

Chapter 9The player's screen

Now, what is shown over the game: the gun, the crosshair, the health and the ammo. First, two settings so it looks right in any window. Open Project > Project Settings:

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

Go back to the 2D tab: that's where the player's screen is laid out. The rectangle is the screen, 1152 × 648.

1
Select Main, + > UI > Image. Call it Gun. Drag sprites/gun.png from the Project panel to its Texture. Set Expand Mode to Ignore Size, and in Layout > Transform: Size 224, 232 and Position 464, 416 (at the bottom, in the middle).
2
Another image, Flash, with sprites/flash.png, Ignore Size, Size 144, 96, Position 504, 340 (at the tip of the gun). Hide it with its eye in the Hierarchy: it's only shown when shooting.
3
+ > UI > Text: Crosshair, with the text +, font size 32 (Theme Overrides > Font Sizes), at Position 566, 300.
4
Two more texts, with font size 28: Health ("HEALTH: 100") at 24, 596, and Ammo ("AMMO: 20") at 910, 596.
5
+ > UI > Panel: Damage, covering the whole screen (Position 0, 0, Size 1152, 648), with a red, half transparent Self Modulate (alpha 90). Hide it: it shows for a moment when a demon bites you.
The player's screen, in the 2D tab.
The player's screen, in the 2D tab.
Tip: instead of dragging the drawings and sounds from the Project panel, you can press the Quick Load icon next to the field (Texture, Sound...): a list opens with the files of the project that fit there; type part of the name (gun, shot...) and press Enter.

Chapter 10Shooting

Ammo and health are global variables: the player, the enemies and the pickups use them. Add BreynFlow to the Health text with these rules:

  • Start. WHEN: Scene Starts. DO: Change Variable health (global): set to 100; ammo (global): set to 20; key (global): set to 0.
  • Show the health. WHEN: Variable Changes: health (global). DO: Change Text of this object to HEALTH: {health}.
  • Show the ammo. WHEN: Variable Changes: ammo (global). DO: Change Text of the text Ammo to AMMO: {ammo}.

Now, on the Player, a new rule, Shoot:

  • WHEN: Key or Button. Click ui_accept and choose mouse_left: the left mouse button.
  • IF: Compare Variable ammo (global) greater than 0.
  • DO: Shoot. In its card, change health to life: the shot takes 25 from the variable "life" of whatever it hits.
  • DO: Change Variable ammo (global): subtract 1.
  • DO: Play Sound sounds/shot.wav.
  • DO: Show or Hide: show the Flash; Wait 0.05 s; hide the Flash.
The player's two rules.
The player's two rules.

Try it: every click sounds, the flash shows and the ammo counter goes down. With 0 ammo, it doesn't shoot any more.

Chapter 11The demon

1
Select Main, + > Enemy (3D). Position: -3, 0, -12 (in the second room). It's already in the group enemies.
2
Unfold it in the Hierarchy, select its Drawing and drag sprites/demon.png to its Texture.
The demon: a drawing that always faces the camera, like in the classics.
The demon: a drawing that always faces the camera, like in the classics.
3
Call the enemy Demon, add BreynFlow to it and make these rules:
  • Start. WHEN: Scene Starts. DO: Change Variable life (of the object: each demon has its own): set to 50. Two shots and it's down.
  • Chase. WHEN: Every Frame. IF: Distance from this object to the Player less than 12. DO: Move Towards (Follow) the Player, speed 2.5, stop distance 1.2. In 3D it walks on the floor and doesn't go through walls.
  • Bite. WHEN: Time Passes: every 1 s. IF: Distance to the Player less than 1.8. DO: health (global): subtract 10; Play Sound hurt.wav; show the Damage panel, wait 0.15 s and hide it.
Tip: to choose the Player or the Damage panel, click the object of the piece and choose An object of the scene...

Chapter 12Hurt and defeated

When a shot hits the demon, it takes 25 from its "life" and sends it the message hit. Two more rules for the Demon:

  • Hurt. WHEN: Message Received: hit. DO: Play Sound pain.wav; Change Property modulate of the Drawing to #ff5050 (red); wait 0.12 s; modulate to white.
  • Defeated. WHEN: Variable Changes: life (of the object). IF: life (of the object) less or equal to 0. DO: Play Sound death.wav; Destroy this object.
The demon's five rules.
The demon's five rules.

Now, a horde: select the Demon and press Ctrl+D twice. Put one copy at 3, 0, -15 and another in the final room, at 2.5, 0, -20.5. Copies share the rules, but each one has its own life.

Fire!
Fire!

Chapter 13Medkits and ammo

1
+ > Pickup (3D): Medkit, at -4, 0, -15. In its Drawing, the texture sprites/medkit.png.
2
Add BreynFlow to it with the rule Pick up: WHEN: Collision (it already says "touches the group player"). IF: health (global) less than 100. DO: health (global): add 25; Play Sound pickup.wav; Destroy this object.
3
Another pickup: Ammo Box, at -4, 0, 1, with sprites/ammo.png. Its rule: WHEN: Collision with player. DO: ammo (global): add 10; sound pickup.wav; Destroy.
The medkit and the ammo box: they float and always face you.
The medkit and the ammo box: they float and always face you.
Tip: the medkit isn't picked up if you already have 100 health: that way you don't waste it.

Chapter 14The red key and the door

The key: another pickup, Key, on the platform: 4.25, 1.5, -13, with sprites/key.png. Its rule: WHEN: Collision with player. DO: key (global): set to 1; Show Message "You have the red key!" for 2 s; sound pickup.wav; Destroy.

The door: Shapes > Cube, called Door, with Size 2.4, 2.8, 0.3 and Position 0, 1.3, -18: it covers the opening of the Door Wall. In Look, the Metal Door texture (it goes once per face). Add BreynFlow to it:

  • Start. WHEN: Scene Starts. DO: open (of the object): set to 0.
  • Open. WHEN: Every Frame. IF: Distance from this object to the Player less than 3; key (global) equal to 1; open (of the object) equal to 0. DO: open: set to 1; sound door.wav; Move To: this object, by an offset of (0, 2.8, 0) in 1 s. It goes up and lets you through.
  • Locked. WHEN: Time Passes: every 2 s. IF: Distance to the Player less than 3; key (global) equal to 0. DO: Show Message "You need the red key" for 1.5 s.
The door's rules.
The door's rules.

Chapter 15The exit and defeat

The exit: Shapes > Cylinder, called Exit, in the final room: Radius 1, Height 0.1 and Position 0, 0.05, -22.5, with a green color in Look. Add BreynFlow to it:

  • Win. WHEN: Every Frame. IF: Distance from this object to the Player less than 1.2; won (of the object) not equal to 1. DO: won: set to 1; Show Message "LEVEL COMPLETE!" for 3 s; Wait 3 s; Restart Scene.

Defeat: on the Health text, one last rule:

  • Die. WHEN: Variable Changes: health (global). IF: health (global) less or equal to 0. DO: Activate or Deactivate: deactivate the Player; Show Message "YOU DIED!" for 2 s; Wait 2 s; Restart Scene.
The exit, in the final room.
The exit, in the final room.

Chapter 16Play!

Show the Ceiling (its eye in the Hierarchy), save (Ctrl+S) and press ▶.

1
Take the ammo in the first room.
2
Go through the doorway: the demons chase you. Aim with the crosshair and shoot with the left click.
3
If they bite you, look for the medkit.
4
Go up the stairs to the platform and take the red key.
5
Open the door, finish off the last demon and step on the exit.

While you play, look at the BreynFlow tab: each rule blinks when it runs. If something doesn't work, you'll see there which condition isn't met.

Chapter 17What now?

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

  • More levels: make another scene with other shapes and, when winning, use Change Scene instead of restarting.
  • Lava: a floor with the Lava texture and a rule "Every frame, if the distance to the Player is less than 2: health subtract 1".
  • More weapons: with "Key or Button" mouse_right, a stronger shot that uses more ammo.
  • Music: a "Scene Starts" rule with Play Music.
  • Your drawings: open the sprites in the Sprites tab and make them yours, or draw other enemies.
  • Convert to Mesh: when the level is finished, Shapes > Convert to Mesh makes it lighter for phones.
Tip: with View as Code (in the rules), BreynFlow shows you how they would look in C#. That way you can see how a first-person game is made inside.

← All the tutorials