{"id":37979,"date":"2024-11-01T10:01:59","date_gmt":"2024-11-01T10:01:59","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37979"},"modified":"2024-11-01T11:32:54","modified_gmt":"2024-11-01T11:32:54","slug":"unity-2d-game-development-create-a-platform-game-including-jumps-obstacles-and-enemies","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37979\/","title":{"rendered":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies."},"content":{"rendered":"<div class=\"post\">\n<p>Hello, everyone! In this post, we will take an in-depth look at how to develop a simple 2D platform game using Unity. This tutorial will guide you step by step through the process of creating a basic platform game that includes the main character&#8217;s jumping ability, obstacles, and enemies. Learn the basics of Unity and more through this course!<\/p>\n<h2>Table of Contents<\/h2>\n<ul>\n<li><a href=\"#section1\">1. Project Setup<\/a><\/li>\n<li><a href=\"#section2\">2. Creating the Basic Character<\/a><\/li>\n<li><a href=\"#section3\">3. Implementing the Jump Mechanism<\/a><\/li>\n<li><a href=\"#section4\">4. Adding Obstacles<\/a><\/li>\n<li><a href=\"#section5\">5. Adding Enemy Characters<\/a><\/li>\n<li><a href=\"#section6\">6. Building and Testing the Game<\/a><\/li>\n<\/ul>\n<h2 id=\"section1\">1. Project Setup<\/h2>\n<p>First, let&#8217;s open the Unity editor and create a new project. Select the &#8216;2D&#8217; template, specify the project name and location, and then click the &#8216;Create&#8217; button. Once the project opens, a basic 2D environment will be prepared.<\/p>\n<h3>Using the Asset Store<\/h3>\n<p>You can utilize the Asset Store to create the basic character, obstacles, and backgrounds needed for your game. Go to &#8216;Window&#8217; -> &#8216;Asset Store&#8217; and enter &#8216;2D Platformer&#8217; or your desired keywords to download the necessary graphic assets.<\/p>\n<h2 id=\"section2\">2. Creating the Basic Character<\/h2>\n<p>Now, let&#8217;s create the basic character. Right-click in the project view and select 2D Object -> Sprite to create a new sprite. Name the created sprite &#8216;Player&#8217;. Then, set the character image for the selected sprite.<\/p>\n<h3>Adding Player Script<\/h3>\n<pre><code>using UnityEngine;\n\npublic class PlayerController : MonoBehaviour\n{\n    public float moveSpeed = 5f;\n    private Rigidbody2D rb;\n    private Vector2 movement;\n\n    void Start()\n    {\n        rb = GetComponent<rigidbody2d>();\n    }\n\n    void Update()\n    {\n        movement.x = Input.GetAxis(\"Horizontal\");\n        movement.y = Input.GetAxis(\"Vertical\");\n    }\n\n    void FixedUpdate()\n    {\n        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);\n    }\n}\n<\/rigidbody2d><\/code><\/pre>\n<p>This script simply implements the player&#8217;s movement. You need to add the &#8216;Rigidbody2D&#8217; component to the player object.<\/p>\n<h2 id=\"section3\">3. Implementing the Jump Mechanism<\/h2>\n<p>Let&#8217;s add a jump mechanism so the player can jump. We will modify the PlayerController script to add this jump feature.<\/p>\n<pre><code>public float jumpForce = 300f;\n    private bool isGrounded;\n    public Transform groundCheck;\n    public LayerMask groundLayer;\n\n    void Update()\n    {\n        movement.x = Input.GetAxis(\"Horizontal\");\n        \n        \/\/ Check for jump\n        if (Input.GetButtonDown(\"Jump\") &amp;&amp; isGrounded)\n        {\n            rb.AddForce(new Vector2(0f, jumpForce));\n        }\n    }\n\n    void FixedUpdate()\n    {\n        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);\n        isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);\n    }\n<\/code><\/pre>\n<p>This code applies the jump force to push the character upward when the jump button is pressed. &#8216;groundCheck&#8217; is used to verify if the player is touching the ground.<\/p>\n<h2 id=\"section4\">4. Adding Obstacles<\/h2>\n<p>Let&#8217;s add obstacles to increase the difficulty of the game. Create a simple obstacle sprite and save it as &#8216;Obstacle&#8217;. Add &#8216;BoxCollider2D&#8217; and &#8216;Rigidbody2D&#8217; components to the obstacle. Set the Body Type of &#8216;Rigidbody2D&#8217; to Kinematic to prevent it from being affected by the physics engine.<\/p>\n<h3>Adding Obstacle Script<\/h3>\n<pre><code>using UnityEngine;\n\npublic class Obstacle : MonoBehaviour\n{\n    void OnCollisionEnter2D(Collision2D collision)\n    {\n        if (collision.gameObject.CompareTag(\"Player\"))\n        {\n            \/\/ Handle Game Over\n            Debug.Log(\"Game Over!\");\n            \/\/ Logic to restart or exit the game can be added\n        }\n    }\n}\n<\/code><\/pre>\n<p>The above code performs a simple function that outputs a &#8216;Game Over&#8217; message when the player collides with the obstacle. Based on this message, you can implement a game over screen or restart logic.<\/p>\n<h2 id=\"section5\">5. Adding Enemy Characters<\/h2>\n<p>Now, let&#8217;s add enemy characters to make the game more interesting. Create the enemy character as a sprite and name it &#8216;Enemy&#8217;. Add &#8216;Rigidbody2D&#8217; and &#8216;BoxCollider2D&#8217; to the enemy character, setting the Body Type of &#8216;Rigidbody2D&#8217; to Kinematic.<\/p>\n<h3>Adding Enemy AI Script<\/h3>\n<pre><code>using UnityEngine;\n\npublic class Enemy : MonoBehaviour\n{\n    public float moveSpeed = 2f;\n    public float moveRange = 3f;\n    private Vector2 startPosition;\n\n    void Start()\n    {\n        startPosition = transform.position;\n    }\n\n    void Update()\n    {\n        float newPosX = Mathf.PingPong(Time.time * moveSpeed, moveRange) + startPosition.x;\n        transform.position = new Vector2(newPosX, transform.position.y);\n    }\n}\n<\/code><\/pre>\n<p>The above code contains a simple AI logic that moves the enemy character back and forth. It uses the &#8216;Mathf.PingPong&#8217; function to set movement within a certain range. You can further complexify the enemy character&#8217;s behavior as needed.<\/p>\n<h2 id=\"section6\">6. Building and Testing the Game<\/h2>\n<p>Now that all elements are in place, let&#8217;s build and test the game. Go to &#8216;File&#8217; -> &#8216;Build Settings&#8217; in the top menu to select the platform to build for. If necessary, add the current scene in &#8216;Scenes in Build&#8217; and click the &#8216;Build&#8217; button.<\/p>\n<p>Once the build is complete, run the game and test the character&#8217;s jumping, obstacles, and enemy behaviors. You can proceed with additional features or debugging to improve the game&#8217;s quality as needed.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we explored the process of creating a simple 2D platform game. By implementing character movement, jumping, obstacles, and enemy AI, we experienced the fundamental skills of game development in Unity. Use this tutorial as a foundation to unleash your creativity and create richer games!<\/p>\n<p>In future posts, we will cover adding in-game UI or implementing audio effects, so stay tuned. May your journey in game development always be enjoyable and creative!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, everyone! In this post, we will take an in-depth look at how to develop a simple 2D platform game using Unity. This tutorial will guide you step by step through the process of creating a basic platform game that includes the main character&#8217;s jumping ability, obstacles, and enemies. Learn the basics of Unity and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37979\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[135],"tags":[],"class_list":["post-37979","post","type-post","status-publish","format-standard","hentry","category-unity-basic"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37979\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello, everyone! In this post, we will take an in-depth look at how to develop a simple 2D platform game using Unity. This tutorial will guide you step by step through the process of creating a basic platform game that includes the main character&#8217;s jumping ability, obstacles, and enemies. Learn the basics of Unity and &hellip; \ub354 \ubcf4\uae30 &quot;Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37979\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T10:01:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:32:54+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.\",\"datePublished\":\"2024-11-01T10:01:59+00:00\",\"dateModified\":\"2024-11-01T11:32:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/\"},\"wordCount\":636,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37979\/\",\"name\":\"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T10:01:59+00:00\",\"dateModified\":\"2024-11-01T11:32:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37979\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37979\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37979\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello, everyone! In this post, we will take an in-depth look at how to develop a simple 2D platform game using Unity. This tutorial will guide you step by step through the process of creating a basic platform game that includes the main character&#8217;s jumping ability, obstacles, and enemies. Learn the basics of Unity and &hellip; \ub354 \ubcf4\uae30 \"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.\"","og_url":"https:\/\/atmokpo.com\/w\/37979\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T10:01:59+00:00","article_modified_time":"2024-11-01T11:32:54+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37979\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37979\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies.","datePublished":"2024-11-01T10:01:59+00:00","dateModified":"2024-11-01T11:32:54+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37979\/"},"wordCount":636,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37979\/","url":"https:\/\/atmokpo.com\/w\/37979\/","name":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies. - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T10:01:59+00:00","dateModified":"2024-11-01T11:32:54+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37979\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37979\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37979\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity 2D Game Development, Create a Platform Game Including Jumps, Obstacles, and Enemies."}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37979"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37979\/revisions"}],"predecessor-version":[{"id":37980,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37979\/revisions\/37980"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}