top of page

Getting Started With Godot: 2D Platformer

Updated: Mar 1


Godot is the lightweight, free and open source game engine. Not only is Godot free to download, it also doesn’t require a subscription or charge royalties for games published with it! This sounds like a pretty good deal (because it is), the only issue is where to get started? Throughout this tutorial, we’ll go through the basics of Godot as well as some useful tips, tricks and resources I’ve picked up along the way.


Step 1: Download the Godot Engine & Making a new project

In this tutorial we’ll be using the latest version of Godot as of now, 3.4.2, which can be downloaded here. Select download and the right version for your operating system. You have the choice of using C# as the scripting language, but for this tutorial we’ll be using the godots built in scripting language GDScript. It’s based on Python and is pretty easy to grasp even with little programming experience.

After it’s downloaded, simply extract the file and launch the engine. From here, click ‘New Project’ and decide where you want to save it. Name it ‘learn Godot’, click create ‘Create Folder’, then ‘Create & Edit’. Now we can start making our game.



Step 2: What Am I looking At? & The First Node

If you have any familiarity with other game engines, the numerous panels and menus should be nothing new but daunting nonetheless. Let’s quickly go through each panel and what it’s function is.




  • Viewport: The Largest panel in the middle of the screen. This is where most of the action will happen, from designing levels in 2D & 3D to writing code.

  • Scene Panel: This is where we can see what Scenes & Nodes we are working with.

  • FileSystem: this is where you manage your resources, like graphics, sounds, music, and scenes.

  • Inspector: This is where we can see the properties of nodes & scenes we have selected.

Since we are starting off with a 2D game, we’ll click the ‘2D Scene’ button in the Scene Panel. A ‘Node2D’ will appear in the Scene Panel and we’ll be taken to the 2D view.



Step 3: Nodes & Scenes



A Node is the most basic element of Godot. They are similar to classes in other programming languages, as they have properties that can be seen in the inspector panel on the right. Node2D only has a few properties, ‘Transform’ and ‘Z Index’. Transform is where the node is on the screen, and Z Index is what it is in front of or behind.




The other most important aspect of nodes is their children. A node can have a number of children nodes, arranged in a tree structure. Different nodes have different properties, for example a parent node might have one child node for sound, one for visuals, one for collision etc.


To add a child node, right click on the Node2D in the scene panel you created and click ‘Add Child Node’. A list of nodes you can add as children pop up. There are a lot of nodes to choose from, so let’s choose something simple. A sprite node will allow us to see an image when running the game. Search for “Sprite” in the search bar in the top, or navigate Node > CanvasItem > Node2D > Sprite. Add sprite, and now the Node2D has a Sprite node as a child.


The sprite doesn’t have a texture so nothing shows up on screen. Some nodes have properties that require resources. Resources are things like files you want to use in your game like music, sounds, images, models, or Godot specific files like shapes. Godot gives us an icon to work with already, so drag icon.png to the ‘Texture’ Property and it should show up on screen.

Now that we know how to add child nodes & resource, it’s time to talk about scenes. By pressing Ctrl + S to save the project, a menu pops up that says ‘Save Scene as…’. A scene in Godot is a collection of nodes that can be treated as a single resource. Bundling many nodes together is very convenient. You could make an enemy with many nodes, save it as a scene, and then instantiate it every time you need an enemy. Since this scene is going to be the first level in the game, save the scene as ‘Level_1.tscn’.


Every game is just a collection of scenes with parents and child scenes & nodes. Press the play button in the top right corner and select which scene we want our game to launch by default. You can select a specific scene, but since we only have the one for now, just hit ‘current scene’. Notice the sprite is in the top left corner of the screen. We can move it into the center of the screen for a better look.



Step 4: Creating the Ground


Now let’s make a character and some ground for it to walk on. We’ll start with the ground first since it’s a little easier. Go to File > New Scene. Instead of a ‘2D Scene’, click ‘Other Node’. Now search & select ‘StaticBody2D’ and create. You will see a warning symbol appear next to the node name. This is because all collision object nodes & their inheritors require a Collision Shape child node. Right click StaticBody2D, add child ‘CollisionShape2D’. CollisionShape2D also has a warning, but it requires a shape resource that can be added in the Inspector panel. In the ‘Shape’ Property, click on the drop down menu and hit ‘New RectangleShape2D’. Click on ‘Rect’ to view the resource properties and change its size to 32x32.



You can see the blue square outlining the collision shape, but since it doesn’t have a sprite, it won’t be visible in game. There are 2 ways to fix this:

  1. Add a sprite node to the StaticBody2D and add in a resource. This is what you’ll want to do for a finished game.

  2. While you’re still getting the game setup, you can make the collision shapes visible in game. In the top menu click ‘Debug’ and check ‘visible collision shapes’. Very useful for prototyping.




Now Ctrl + S to save the the scene, call it ‘Ground.tscn’ and close that scene. Now in Level_1.tscn, Right click Node2D, select ‘Instance Child Scene’ and select Ground. And now we have a very easy way to make the ground! Just instantiate a few more ground tiles and we have a nice floor.



(there is a slightly better way of making a ground, this is just the simplest way for now.)

If you want your nodes to snap to a grid, you can use these buttons:



Step 5: Creating A Character & Starting Scripting


And what would a platformer be without a platformer? In much the same way as the ground, create a new scene and select ‘other node’. This time search for ‘KinematicBody2D’. Add a CollisionShape2D, add a shape to that. Feel free to add a sprite node. Save the scene as “Player.tscn” and instance it in Level_1.tscn. Click and drag the player above the platform. Pressing play now doesn’t do much, the character just stays in place. To make the character move, we have to write some code. Go to the player scene, right click KinematicBody2D and select ‘Attach Script’. A couple settings appear, but for now just select ‘create’. We are now in the scripting menu.





GDScript is similar to python. Blocks are indent-based and dynamically typed. A few elelmentes show up by default.

  • Comments Start with #

  • A variable starts with the keyword ‘var’

  • A function starts with the keyword ‘func’

Since GDScripts are attached to nodes, you can access the properties and functions of that node in the script. All nodes have a function called ‘_physics_process(delta)’ that is called once every frame. This is good for handling physics calculations, such as a moving character. The reason we used KinimaticBody2D is because it has a function that allows us to move it and detect collisions. Delete all the code except ‘extends KinematicBody2D’.

In the script, type:




extends KinematicBody2D

func _physics_process(delta):
	if Input.is_action_pressed("ui_accept"): print("Hello World!")





This checks every frame to see if the enter button is pressed. If it is, it will print “Hello World!” to the output window. Good! Now we can start programming the movement. A Vector2 is a 2 dimensional vector with x & y values that we can use to represent movement in the game. If the right arrow is pressed, the x vector will be set to 100, and if left is pressed it will be set to -100. Then the KinematicBody2D function ‘move_and_slide’ will be called, which moves the player along the vector given in the first arguments:


extends KinematicBody2D



func _physics_process(delta):
	var moveVector = Vector2.ZERO
	if Input.is_action_pressed("ui_right"): moveVector.x = 100
	if Input.is_action_pressed("ui_left"): moveVector.x = -100
	move_and_slide(moveVector)


Now the player should be able to move back and forth. However, you’ll notice if you placed the player slightly above the ground, they won’t fall to the ground. We’ll need to program this as well.




extends KinematicBody2D

func _physics_process(delta):
	var moveVector = Vector2.ZERO
	if Input.is_action_pressed("ui_right"): moveVector.x = 100
	if Input.is_action_pressed("ui_left"): moveVector.x = -100
	if not is_on_floor(): moveVector.y = 200
	move_and_slide(moveVector, Vector2.UP)




The ‘is_on_floor()’ function checks if the bottom of the player collided with the floor. However we will also have to specify which direction is up. The Vector2 object has a constant UP we can use. The up direction is the optional second argument for the ‘move_and_slide’ function.

Now our character can move and falls to the ground, but we should probably add jumping too. Before we do that, we should do some housekeeping to make our lives easier. It’s usually a good idea to have variables for character properties, so let’s do that:



extends KinematicBody2D

var speed = 200
var gravity = 50
var moveVector = Vector2.ZERO

func _physics_process(delta):
	if Input.is_action_pressed("ui_right"): moveVector.x = speed
	elif Input.is_action_pressed("ui_left"): moveVector.x = -speed
	else: moveVector.x = 0
	if not is_on_floor(): moveVector.y += gravity
	move_and_slide(moveVector, Vector2.UP)


Now we only have to change one value for our speed and one for how fast we fall. We are also now adding our falling speed every frame rather than just setting it once. This means we accelerate downwards faster over time. Finally, let’s add a jump button.



extends KinematicBody2D

var speed = 200
var gravity = 50
var jump = -750
var moveVector = Vector2.ZERO

func _physics_process(delta):
	if Input.is_action_pressed("ui_right"): moveVector.x = speed
	elif Input.is_action_pressed("ui_left"): moveVector.x = -speed
	else: moveVector.x = 0
	if is_on_floor():
		if Input.is_action_pressed("ui_up"): moveVector.y = jump
		else: moveVector.y = 0
	if not is_on_floor(): moveVector.y += gravity
	move_and_slide(moveVector, Vector2.UP)


Now pressing up on the keyboard will send your character into the air!


In theory, you’ve learned everything you need to know to start making games with Godot. Of course, there is so much left to learn just about Godot that can’t be covered in a single tutorial. As much as I would like an all in one tutorial, it’s likely there will be a part 2 for some more polish. For now, we covered the most important concepts: nodes, scenes, resources, and scripting. There’s lots left to learn so here are some tips I found useful:

  • Read the Godot Docs! There is information about everything, including some more specific tutorials and more in depth discussions of topics covered here. This tutorial was to get you started, these docs are where you can go from here.

  • Use the ‘Open Documentation’ on nodes. This brings you to the documentation on all the properties & functions of the nodes. These are also available online.

  • Download some of the demo projects for Godot. Seeing how other people implement things like camera controls or use certain nodes can really help & inspire.

950 views0 comments
bottom of page