{"id":39,"date":"2024-08-24T15:05:19","date_gmt":"2024-08-24T15:05:19","guid":{"rendered":"https:\/\/opensourcegamers.com\/wp-blog\/?p=39"},"modified":"2024-08-24T15:17:30","modified_gmt":"2024-08-24T15:17:30","slug":"how-to-make-a-simple-2d-platformer-in-godot-4","status":"publish","type":"post","link":"https:\/\/opensourcegamers.com\/wp-blog\/2024\/08\/24\/how-to-make-a-simple-2d-platformer-in-godot-4\/","title":{"rendered":"How To Make a Simple 2d Platformer in Godot 4"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"547\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3-1024x547.png\" alt=\"\" class=\"wp-image-40\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3-1024x547.png 1024w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3-300x160.png 300w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3-768x410.png 768w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3-1536x820.png 1536w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-3.png 1919w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Okay, so you want to make a 2d platforming game in godot, but you dont know where to start? Well, I can help.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Step One &#8211; Plugins to use<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div style=\"height:49px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>For making the game, the plugin i would recommend is called &#8220;Platformer Controller 2D&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-4-1024x606.png\" alt=\"\" class=\"wp-image-41\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-4-1024x606.png 1024w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-4-300x177.png 300w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-4-768x454.png 768w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-4.png 1141w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:52px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This plugin adds basic collision and movement for a player character.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Step 2: Setting Up Controls<\/p>\n\n\n\n<p>Setting up controls in Godot was a bit confusing to me at first, so let me explain<\/p>\n\n\n\n<div style=\"height:43px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>First, go to the project tab<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"326\" height=\"70\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055347.png\" alt=\"\" class=\"wp-image-11\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055347.png 326w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055347-300x64.png 300w\" sizes=\"auto, (max-width: 326px) 100vw, 326px\" \/><\/figure>\n\n\n\n<p>Select project settings, and then go to input map<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"71\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055415.png\" alt=\"\" class=\"wp-image-12\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055415.png 372w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/Screenshot-2024-08-24-055415-300x57.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/figure>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"503\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-5.png\" alt=\"\" class=\"wp-image-42\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-5.png 887w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-5-300x170.png 300w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-5-768x436.png 768w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><\/figure>\n\n\n\n<p>Now, open the demo scene made by the plugin, and let us begin.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Step 3: Finishing Player Setup<\/p>\n\n\n\n<p>when in the demo scene, click on the &#8220;PlatformerController2D&#8221; node<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6-1024x576.png\" alt=\"\" class=\"wp-image-43\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6-1024x576.png 1024w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6-300x169.png 300w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6-768x432.png 768w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6-1536x864.png 1536w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-6.png 1919w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then, go to the right side and change the input options to the correct key names<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"253\" height=\"143\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-7.png\" alt=\"\" class=\"wp-image-44\"\/><\/figure>\n\n\n\n<p>To make the camera move with the player, add a camera2d node to the platformercontroller2d node.<\/p>\n\n\n\n<p>Now, play the game, select the scene, and it should work!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Step 4: Making Platforms<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"236\" height=\"78\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-8.png\" alt=\"\" class=\"wp-image-45\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\"> Step 5: The Goal<\/p>\n\n\n\n<p>For the goal, make an area2d, and make a signal connecting it to the platformercontroller2d<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"344\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-11.png\" alt=\"\" class=\"wp-image-48\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-11.png 647w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-11-300x160.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p>Now, make a level Completed scene (or you could connect it to a new level, either way steps are the same)<\/p>\n\n\n\n<p>Put the following code under signal function (change the name goal to whatever you want to switch to)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>get_tree().change_scene_to_file(\"res:\/\/goal.tscn\")<\/code><\/pre>\n\n\n\n<p>You can add a texture by adding a color rect or texture rect<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Step 6: the death function<\/p>\n\n\n\n<p>let us say you want to make it so if the player falls, they reset to the spawn position.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>create the same node tree and signal as with the goal, with these differences<\/p>\n\n\n\n<p>first, make it big and under the platforming stuff.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"697\" height=\"317\" src=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-12.png\" alt=\"\" class=\"wp-image-49\" srcset=\"https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-12.png 697w, https:\/\/opensourcegamers.com\/wp-blog\/wp-content\/uploads\/2024\/08\/image-12-300x136.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/figure>\n\n\n\n<p>next, reconnect it and this time use this script. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>get_tree().reload_current_scene()<\/code><\/pre>\n\n\n\n<p>now, it will reload the scene when the area is entered.<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>to make things like spikes, use the same process as the barrier, but add a texture and make it smaller.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_siteseo_robots_primary_cat":"","footnotes":""},"categories":[1],"tags":[14,3,5,6,4,7,12,10,11,13,9],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-gamedev","tag-godot","tag-godot-4","tag-godot-4-tutorial","tag-godot-4-0","tag-godot-tutorial","tag-how-to-code","tag-how-to-code-a-2d-platformer","tag-how-to-make-a-2d-platformer","tag-how-to-make-a-game","tag-how-to-make-a-platformer-in-godot"],"_links":{"self":[{"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":1,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":50,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/posts\/39\/revisions\/50"}],"wp:attachment":[{"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opensourcegamers.com\/wp-blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}