Game crafting with Godot, good my lord!

Skip to content

This doth be a machine-wrought text which may contain errors!

Whence doth this information spring?

Much hereof is but a recounting of Godot’s official documentation. Underneath ye shall find some helpful links to the said documentation (which I do most heartily commend above this upon Piggy, yet if thou dost prefer this, use it freely!)

Useful Resources:

What of the artistry, must I fashion it with mine own hands?

Nay, good sirs! Ye may discover a wealth of free treasures here:

Other game engines?

If thou dost prefer it, thou mayest employ other game engines. Examples of such engines are:

There exist many others also, seek freely if thou wouldst essay something else!

What is Godot?

Godot (Pronounced Guh-doh), doth be a ‘Game Engine’. To speak plainly, ‘tis a program which doth allow thee to create games (or common programs, shouldst thou desire). Godot can accomplish near all that other game-engines can, both 2D and 3D.

Examples of games crafted in Godot: Godot Showcase

‘Tis not solely Indie games which have been wrought in Godot, Sonic Colors Ultimate is made with Godot!

How Doth One Obtain Godot?

Thou mayest either download Godot from:

Simply download and install (or run upon Steam).

Set Forth a Project!

When thou dost commence Godot, this window shall appear before thee:

Godot Prosjekt

Here art thou asked concerning the tongue of programming, GDScript or C#. GDScript doth bear a great likeness unto Python.

Differences ‘twixt GDScript and Python (without colours):

def hello():
    text = "Hello world!"

    print(text)
func hello():
    var text = "Hello world!"

    print(text)

For variables in Python, thou needest but write the name of the variable. In GDScript, thou must write var first. To fashion functions, thou dost write func in place of def.

Scenes & Nodes

One of the most principal concepts within Godot doth be Scenes and Nodes. We may begin with Nodes. A Node is an object within Godot, and ‘tis may represent all things. It may be something which doth represent a player, an enemy, a button in a menu, text upon the screen, all manner of things. Scenes are a gathering of Nodes.

Here shall we create a most simple example.

Part 1a - Set Up the “Player” Scene

Upon the uppermost part of the Godot window, press the “2D” button to alter the view to a 2D prospect.

On the left side of the window, ye shall behold the following interface:

Create Scene

Press the “Other Node” button, and seek for “CharacterBody2D”, choose it, and press “Create”. This is a node used for a 2D player. Perchance ye observe a warning triangle ⚠️ beside the “CharacterBody2D” node. This doth signify it lacketh certain things it doth desire.

If thou right-click upon the node, there is a “+ Add Child Node…” button. Use this and add two nodes, Sprite2D and CollisionShape2D. Sprite2D is used to add some graphics unto the player, whilst the other is used to check for collisions. Thou mayest also give them names, if it maketh it easier to keep track of things. I have given mine CharacterBody2D the name “Player”. Thus should the scene appear now:

Scene currently

Part 1b - Rectifying ⚠️ upon CollisioShape2D

The warning triangle in this instance doth signify that the CollisioShape2D lacketh actual collision. This mayst thou rectify by pressing upon the node (to the left), whereupon a panel shall appear on the right side. Here thou shalt find a multitude of information concerning the node, which thou mayest amend. Prithee, play about with that which is there. But ‘tis upon “Shape” that we shall focus, setting it to, for example, RectangleShape2D. ‘Tis not of great import, for we shall not employ the collisions here.

Del 1c - To Add a Sprite, Graphics

Shouldst thou press upon Sprite2D at the left hand, ‘twill bring forth the field at the right, where doth stand writ “Texture”. Here mayst thou place an image for the player. ‘Tis but to drag an image and release it within the field.

Thus will it appear after adding a sprite.

Sprite menu

Part 2 - Adding Input, Controls

At the pinnacle of the window doth reside a menu, “Scene - Project - Debug - Editor - Help”. Press upon “Project” and thereafter “Project Settings”. Here shall appear a menu with a multitude of settings. Press upon “Input Map”. Here may ye set up buttons upon the keyboard.

  • In the “Add New Action” field, write “left” and then press “Add”.
  • Thereafter, add “right”, “up” and “down”.
  • These shall be known as “Actions”
  • Upon each “Action” may ye lay in buttons by pressing the + button to the right.

Plus button

  • Here ‘tis but to press upon the keyboard, then press Add.
  • Add buttons upon all actions.

Part 3 - Adding a Script to Govern the Player.

To be able to add game logic, that is, to do something with the player, the background, or what else it may be in the game, we require a script. Scripts are code, and may be writ in two tongues, GDScript or C#, GDScript being the default.

  • Press upon the “CharacterBody2D” node (I have named it “Player”).
  • Press upon the “Attach Script” button (see below)

Attach script button

  • Here shall appear a window wherein ye may choose a language (choose GDScript) and a path (leave it as it stands, but ye may give it a name), and then press forward. Here shall appear a “Script” window. Little doth it contain at the beginning.

extends CharacterBody2D
# Dette er en enkel karakterkontroller.
# 'Tis a simple character controller, forsooth.
# Hastighet for bevegelse.
# Speed at which the character doth move.
var speed = 200

func _physics_process(delta):
    # Hent input fra spilleren.
    # Gather input from the player, pray thee.
    var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")

    # Beveg karakteren.
    # Move the character, good sir.
    velocity.x = direction.x * speed
    velocity.y = direction.y * speed

    move_and_slide()

Hark! This code doth presently declare but this: that the same shall pertain to a node of the sort “CharacterBody2D,” which, in sooth, is our player.

We shall add a function here, which we shall employ to manipulate the player:

extends CharacterBody2D

func _physics_process(delta: float) -> void:
   # Dette er en tom funksjon.
   # 'Tis a void function, forsooth.
   return

Physics Process?

_physics_process is a function which doth update with each and every “frame”, that is to say, some sixty times per second (by default). There existeth another function, named simply _process, which doth update continually. Shouldst thou desire that thy player move at a steady pace, then use _physics_process.

Hark, ‘tis here we shall add the code which doth convey the player.

Part 4 - Basic Input

In Part 2, didst thou add input buttons? Now shall we employ them. There existeth a built-in object hight Input which we may use to ascertain if the player hath pressed that which we have set forth in the “Input Map”.

Pray, attempt to insert this code into thy _physics_process code:

if Input.is_action_pressed('right'):
   # Flytt karakteren mot høyre.
   # Hither doth the character move towards the right.
   velocity.x = 100

move_and_slide()

What doth be move_and_slide()?

move_and_slide() is a function built within Godot, employed when we desire to truly move that upon which ‘tis used. Without this, the player shall not stir.

Warning

The space ‘twixt lines doth hold a mighty sway, even as ‘tis done in Python’s way.

What doth betide when thou dost commence the programme by pressing upon the play button within the Godot window, and then dost press “right”?

If naught doth occur now:

  • Hast thou remembered to set up aught within the “Input Map”?
  • Hast thou writ right and not Right? That is to say, is that which thou didst write in the code the selfsame as the name within the input map?

Helse koden så langt
extends CharacterBody2D

func _physics_process(delta: float) -> void:
   if Input.is_action_pressed('right'):
       velocity.x = 100

   move_and_slide()

‘Tis a most humble offering of the code wrought thus far.

extends CharacterBody2D

func _physics_process(delta: float) -> void:
   if Input.is_action_pressed('right'):
       velocity.x = 100

   move_and_slide()

Hark, now attempt to add code for 'left', 'up', 'down'.

What must velocity.x be for left? And what for up and down?

Helse koden nå
extends CharacterBody2D

func _physics_process(delta: float) -> void:
   if Input.is_action_pressed('right'):
       velocity.x = 100
   if Input.is_action_pressed('left'):
       velocity.x = -100
   if Input.is_action_pressed('down'):
       velocity.y = 100
   if Input.is_action_pressed('up'):
       velocity.y = -100

   move_and_slide()

Part the Fifth - Rectifying the Code

Perchance ye do observe that the player doth not cease motion when thou release a direction. ‘Tis a matter we may amend anon!

Ere all the if-clauses, add a line which doth set velocity to naught. This may be done by writing velocity = Vector2()

All speeds and directions in Godot are vectors, a mathematical conceit we shall not delve into at this present, yet should ye desire further knowledge of its meaning, ye may repair hither: Wikipedia vectors.

Helse koden nå
extends CharacterBody2D

func _physics_process(delta: float) -> void:
   velovity = Vector2()

   if Input.is_action_pressed('right'):
       velocity.x = 100
   if Input.is_action_pressed('left'):
       velocity.x = -100
   if Input.is_action_pressed('down'):
       velocity.y = 100
   if Input.is_action_pressed('up'):
       velocity.y = -100

   move_and_slide()

Lo, the entire code doth now appear,

That doth extend the CharacterBody2D, ‘tis true.

And in the physics process, when time doth flow,

The velocity is set to naught, as ye may know.

If the right key be pressed, with eager hand,

Then shall the velocity on the x-axis expand.

Should the left key be pressed, with purpose keen,

The velocity on the x-axis shall wane, I ween.

If down be pressed, with gravity’s embrace,

The velocity on the y-axis shall find its place.

And should up be pressed, with lightness and grace,

The velocity on the y-axis shall quicken its pace.

Then move and slide, with nimble stride,

And let the character through the world abide.

When thou dost commence the game anon, thou mayest move the player about:

Furthermore, ye may amend the code such that the speed be not merely a number, but may be stored elsewhere.

Forsooth, thou mayest (ere the function) add a constant to keep track of the speed.

Helse koden til slutt med const
extends CharacterBody2D

const SPEED = 100

func _physics_process(delta: float) -> void:
   velovity = Vector2()

   if Input.is_action_pressed('right'):
       velocity.x = SPEED
   if Input.is_action_pressed('left'):
       velocity.x = -SPEED
   if Input.is_action_pressed('down'):
       velocity.y = SPEED
   if Input.is_action_pressed('up'):
       velocity.y = -SPEED

   move_and_slide()

Lo, the whole code at the last, with const declared,

extends CharacterBody2D

const SPEED = 100

func _physics_process(delta: float) -> void:
   velocity = Vector2()

   if Input.is_action_pressed('right'):
       velocity.x = SPEED
   if Input.is_action_pressed('left'):
       velocity.x = -SPEED
   if Input.is_action_pressed('down'):
       velocity.y = SPEED
   if Input.is_action_pressed('up'):
       velocity.y = -SPEED

   move_and_slide()

Part 6 - Sport and Play Thyself!

If ye return to the first part, Helpful Resources, ye may find what ye can continue to sport with.

After this, ye may attempt to create thine own game. What ye fashion is left to thine own devising! Shouldst thou desire to create something wholly new, do so! If ye wouldst attempt to imitate a game which doth already exist, do so! The best way to learn is by trying!