Game makin' with Godot, yeehaw šŸ¤–

Skip to content

This here’s a machine-translated text that might have some errors in it!

Where does this information come from?

A whole heap of this is just a retelling of Godot’s official documentation. Down below you’ll find some useful links to the official documentation (which I reckon you oughta use over this here on Piggy, but if you prefer this one, go right ahead!)

Useful Resources:

What about graphics, do I gotta make ā€˜em myself?

Nope! Y’all can find a heap o’ free stuff right here:

Other game engines?

If you prefer, you can use other game engines. Examples of other game engines are:

There are many others too, feel free to search if you want to try something different!

What in Tarnation is Godot?

Godot (Pronounced Guh-doh), is a ā€˜Game Engine’. To put it plain and simple, it’s a program that lets ya make games (or regular programs if ya feel like it). Godot can do most anything other game engines can do, both 2D and 3D.

Examples of games made in Godot: Godot Showcase

It ain’t just Indie games that’ve been made in Godot, Sonic Colors Ultimate was made with Godot! šŸ¦”šŸ¦”šŸ¦”

How Do Ya Get Yer Hands on Godot?

Ya can either download Godot from:

Just download ā€˜er and install (or run ā€˜er on Steam).

Set Up a Project!

When you start Godot, you get this window:

Godot Project

Here you’re asked about programming language, GDScript or C#. GDScript is mighty similar to Python.

Differences between GDScript and Python (without colors):

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

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

    print(text)

For variables in Python, you just gotta write the name of the variable. In GDScript, you gotta write var first. To make functions, you write func instead of def.

Scenes & Nodes

One o’ the most important concepts within Godot is Scenes and Nodes. We can start with nodes. A node is an object in Godot, and it can represent just ā€˜bout anything. It can be somethin’ representin’ a player, an enemy, a button in a menu, text on the screen, all sorts o’ things. Scenes are a collection o’ nodes.

Here we’re gonna make a real simple example.

Part 1a - Set Up the ā€œplayerā€ Scene

At the top of the Godot window, press the ā€œ2Dā€ button to change the view to a 2D view.

On the left side of the window, you’ll see the following interface:

Create Scene

Press the ā€œOther Nodeā€ button, and search for ā€œCharacterBody2Dā€, select it and press ā€œCreateā€. This here’s a node used for a 2D player. You might notice a warnin’ triangle āš ļø next to the ā€œCharacterBody2Dā€ node. That’s ā€˜cause it’s missin’ a few things it’d like to have.

If you right-click on the node there’s a ā€œ+ Add Child Nodeā€¦ā€ button. Use that and add two nodes, Sprite2D and CollisionShape2D. Sprite2D is used to add some graphics to the player, while the other one’s used to check for collisions. You can also give ā€˜em names if it makes it easier to keep track of things. I’ve given my CharacterBody2D the name ā€œPlayerā€. Your scene should look like this now:

Scene currently

Part 1b - Fixin’ āš ļø on CollisionShape2D

The warnin’ triangle in this here case is that the CollisionShape2D is missin’ actual collision. You can fix this by clickin’ on the node (on the left), then a panel’ll pop up on the right side. Here you get a whole mess o’ information ā€˜bout the node you can change. Feel free to mess around with what’s there. But the one we wanna focus on is ā€œShapeā€, set this to somethin’ like RectangleShape2D. It ain’t all that important, we ain’t gonna be usin’ the collisions here.

Part 1c - Addin’ a Sprite, Graphics

If ya click on Sprite2D on the left, it’ll bring up the fields on the right, where it says ā€œTextureā€. Here ya can put in a picture for the player. Just drag a picture in and drop it in the field.

Here’s what it’ll look like after addin’ a sprite.

Sprite menu

Part 2 - Addin’ Input, Controls

At the top o’ the window, there’s a menu, ā€œScene - Project - Debug - Editor - Helpā€. Press on ā€œProjectā€ and then ā€œProject Settingsā€. Here ya get a menu with a whole heap o’ settings. Press on ā€œInput Mapā€. Here ya can set up buttons on the keyboard.

  • In the ā€œAdd New Actionā€ field, write ā€œleftā€ then press ā€œAddā€.
  • Then add ā€œrightā€, ā€œupā€ and ā€œdownā€.
  • These here are known as ā€œActionsā€
  • On each ā€œActionā€ ya can add buttons by pressin’ the + button to the right.

Plus button

  • Here ya just gotta press on the keyboard, then press Add.
  • Add buttons on all actions.

Part 3 - Addin’ a Script to Control the Player.

To be able to add game logic, meanin’ do somethin’ with the player, the background, or whatever it might be in the game, we need a script. Scripts are code, and can be written in two languages, GDScript or C#, GDScript is the default.

  • Press on the ā€œCharacterBody2Dā€ node (I done called it ā€œPlayerā€).
  • Press on the ā€œAttach Scriptā€ button (see below)

Attach script button

  • Here ya get a window where ya can choose a language (choose GDScript) and a path (just leave it as it is, but ya can give it a name), then press on further. Here ya get a ā€œScriptā€ window. Ain’t much here to start with.

extends CharacterBody2D
# Dette er hovedskriptet for spilleren.
# This here's the main script fer the player.
# Her defineres spillerens bevegelse og handlinger.
# Here's where we define how the player moves 'n' what they do.

var speed = 200
# Hastighet spilleren beveger seg med.
# How fast the player moves, ya see.

func _physics_process(delta):
    # Beveg spilleren basert pƄ input.
    # Move the player 'round based on what ya press.
    var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    velocity = direction * speed
    move_and_slide()

The only thang this here code’s sayin’ right now is that the code’s gotta belong to a node of the ā€œCharacterBody2Dā€ type, which is our player.

We’re gonna add a function here that we’re gonna use to wrangle the player:

extends CharacterBody2D

# Dette er en tom funksjon.
# This here is a empty function.
func _physics_process(delta: float) -> void:
    return

Physics Process?

_physics_process is a function that gets updated every single ā€œframeā€, meanin’ ā€˜round 60 times a second (default). There’s another function just called _process, which updates all the time. If ya want yer player movin’ at a steady pace, ya use _physics_process.

Right here’s where we’re gonna put the code that moves the player ā€˜round.

Part 4 - Basic Input

In Part 2, ya added input buttons, now we’re gonna use ā€˜em. There’s a built-in object called Input that we can use to check if the player’s pressed what we’ve set up in the ā€œInput Mapā€.

Try addin’ this here code into yer _physics_process code:

if Input.is_action_pressed('right'):
    velocity.x = 100

# Flytt og skli.
# Move 'n slide.
move_and_slide()

What is move_and_slide()?

move_and_slide() is a built-in function in Godot that’s used when we actually want to move whatever we’re applyin’ it to. Without this here function, the player ain’t gonna be movin’ a muscle.

Warning

The spacing on the lines is mighty important, this here is the same as in Python.

What happens when ya start the program by pressin’ the play button in the Godot window, then pressin’ ā€œrightā€?

If nothin’ happens now:

  • Did ya remember to set somethin’ up in the ā€œInput Mapā€?
  • Did ya write right and not Right? Meanin’, is what ya wrote in the code the same as the name in the input map?

All the code so far
extends CharacterBody2D

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

    move_and_slide()

Try now to add code for 'left', 'up', 'down'.

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

Hele 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 5 - Fixin’ the Code

Now, ya might notice the player don’t stop when ya let go of a direction. We can fix that right now!

Before all them if statements, add a line that sets velocity to 0. Ya can do that by writin’ velocity = Vector2()

All speeds and directions in Godot are vectors, this here’s a math concept we ain’t gonna get into right now, but if ya’re wonderin’ more ā€˜bout what that means, ya can mosey on over here: Wikipedia vectors.

The whole code now
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()

When ya start the game now, ya can move the player around:

Further, ya’ll can fix the code to make the speed not just be a number, but can be stored somewhere else.

Ya can, fer instance (before the function) add a constant that keeps track of the speed.

Hele 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()

Part 6 - Go On and Play Around!

If y’all head back to the first part, Useful Resources, you can find what you can continue to play with.

After this, you can try makin’ yer own game. What you build is up to you! If you wanna make somethin’ brand new, go right ahead! If you wanna try copyin’ a game that already exists, do that too! Best way to learn is by tryin’!