How To Make a Simple 2d Platformer in Godot 4

Okay, so you want to make a 2d platforming game in godot, but you dont know where to start? Well, I can help.


Step One – Plugins to use

In godot, there is a really useful tool called the asset library. the asset library is a place where people can publish their code for other people to use freely.

For making the game, the plugin i would recommend is called “Platformer Controller 2D”

This plugin adds basic collision and movement for a player character.


Step 2: Setting Up Controls

Setting up controls in Godot was a bit confusing to me at first, so let me explain

First, go to the project tab

Select project settings, and then go to input map

In input map, you are able to make it so you can easily listen to keyboard actions. below i set it up for WASD and Space.

Now, open the demo scene made by the plugin, and let us begin.


Step 3: Finishing Player Setup

when in the demo scene, click on the “PlatformerController2D” node

Then, go to the right side and change the input options to the correct key names

To make the camera move with the player, add a camera2d node to the platformercontroller2d node.

Now, play the game, select the scene, and it should work!


Step 4: Making Platforms


Step 5: The Goal

For the goal, make an area2d, and make a signal connecting it to the platformercontroller2d

Now, make a level Completed scene (or you could connect it to a new level, either way steps are the same)

Put the following code under signal function (change the name goal to whatever you want to switch to)

get_tree().change_scene_to_file("res://goal.tscn")

You can add a texture by adding a color rect or texture rect


Step 6: the death function

let us say you want to make it so if the player falls, they reset to the spawn position.

create the same node tree and signal as with the goal, with these differences

first, make it big and under the platforming stuff.

next, reconnect it and this time use this script.

get_tree().reload_current_scene()

now, it will reload the scene when the area is entered.

to make things like spikes, use the same process as the barrier, but add a texture and make it smaller.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *