{"id":32001,"date":"2024-11-01T09:04:50","date_gmt":"2024-11-01T09:04:50","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32001"},"modified":"2024-11-01T12:37:00","modified_gmt":"2024-11-01T12:37:00","slug":"%ec%9c%a0%eb%8b%88%ed%8b%b0-%ea%b8%b0%ec%b4%88-%ea%b0%95%ec%a2%8c-%ec%98%a4%eb%b8%8c%ec%a0%9d%ed%8a%b8%ec%9d%98-%ec%b6%a9%eb%8f%8c-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32001\/","title":{"rendered":"Unity basics course: Object collision"},"content":{"rendered":"<p><body><\/p>\n<p>Unity is a powerful game engine that helps create a variety of games easily. In this tutorial, we will cover the basics of object collision handling in Unity. Collisions are an important element that create interactions between characters, enemies, and items in a game. Therefore, understanding collisions is the first step towards successful game development.<\/p>\n<h2>1. Understanding the Physics System in Unity<\/h2>\n<p>Unity manages interactions between objects through its built-in physics engine. The physics system is primarily implemented using the <strong>Rigidbody<\/strong> and <strong>Collider<\/strong> components.<\/p>\n<h3>1.1 Rigidbody<\/h3>\n<p><strong>Rigidbody<\/strong> is a component that gives physical properties to an object. It allows the object to be affected by gravity or to be moved through applied forces. To use Rigidbody, follow these steps:<\/p>\n<ol>\n<li>Select the game object.<\/li>\n<li>Click the <strong>Add Component<\/strong> button in the Inspector window.<\/li>\n<li>Select <strong>Rigidbody<\/strong> from the <strong>Physics<\/strong> section.<\/li>\n<\/ol>\n<h3>1.2 Collider<\/h3>\n<p>A collider (<strong>Collider<\/strong>) is used to define the physical shape of an object. Colliders are not visually seen but enable collision detection. Unity has several types of colliders:<\/p>\n<ul>\n<li><strong>Box Collider<\/strong>: A rectangular prism-shaped collider.<\/li>\n<li><strong>Sphere Collider<\/strong>: A spherical collider.<\/li>\n<li><strong>Capsule Collider<\/strong>: A capsule-shaped collider.<\/li>\n<li><strong>Mesh Collider<\/strong>: A complex mesh-shaped collider.<\/li>\n<\/ul>\n<h2>2. Collisions and Triggers Between Objects<\/h2>\n<p>A collision occurs when two or more objects come into contact with each other. In Unity, there are two main ways to handle collisions:<\/p>\n<ul>\n<li><strong>Collision<\/strong><\/li>\n<li><strong>Trigger<\/strong><\/li>\n<\/ul>\n<h3>2.1 Collision<\/h3>\n<p>When objects collide, both objects will generate a physical response. To detect and respond to a collision, both objects must have a <strong>Rigidbody<\/strong> and <strong>Collider<\/strong> attached.<\/p>\n<h4>Handling Collisions<\/h4>\n<p>In Unity, methods such as <code>OnCollisionEnter<\/code>, <code>OnCollisionStay<\/code>, and <code>OnCollisionExit<\/code> can be used to handle object collisions. By defining these methods in a script, the logic for handling collisions can be implemented.<\/p>\n<pre><code>void OnCollisionEnter(Collision collision) {\n    \/\/ Code executed when a collision starts\n    Debug.Log(\"Collision occurred: \" + collision.gameObject.name);\n}<\/code><\/pre>\n<h3>2.2 Trigger<\/h3>\n<p>A trigger is an object that does not generate a physical response even when a collision occurs. This means that even if objects overlap, there will be no response, only events will occur. To handle triggers, you must enable the <strong>Is Trigger<\/strong> option on the collider.<\/p>\n<h4>Handling Triggers<\/h4>\n<p>To handle triggers, methods like <code>OnTriggerEnter<\/code>, <code>OnTriggerStay<\/code>, and <code>OnTriggerExit<\/code> are used.<\/p>\n<pre><code>void OnTriggerEnter(Collider other) {\n    \/\/ Code executed when a trigger occurs\n    Debug.Log(\"Trigger occurred: \" + other.gameObject.name);\n}<\/code><\/pre>\n<h2>3. Handling Collisions in a Real Project<\/h2>\n<p>Now, let&#8217;s create a simple sample project to understand how to handle collisions. In this project, we will implement a feature that makes the enemy object disappear when it collides with the player.<\/p>\n<h3>3.1 Project Setup<\/h3>\n<p>After creating a new 3D project in the Unity editor, add the following items:<\/p>\n<ul>\n<li>Player Object: Add a cube-shaped object and attach <strong>Rigidbody<\/strong> and <strong>Box Collider<\/strong>.<\/li>\n<li>Enemy Object: Add another cube-shaped object and attach <strong>Box Collider<\/strong>.<\/li>\n<\/ul>\n<h3>3.2 Writing the Script<\/h3>\n<p>Now, let&#8217;s write a script that makes the enemy object disappear when it collides with the player.<\/p>\n<pre><code>using UnityEngine;\n\npublic class Enemy : MonoBehaviour {\n    void OnCollisionEnter(Collision collision) {\n        if (collision.gameObject.CompareTag(\"Player\")) {\n            \/\/ Destroy the enemy object when colliding with the player\n            Destroy(gameObject);\n            Debug.Log(\"The enemy object has been destroyed by the player.\");\n        }\n    }\n}<\/code><\/pre>\n<h3>3.3 Setting the Tag<\/h3>\n<p>Add a tag called <strong>Player<\/strong> to the player object. This allows the script to identify the player.<\/p>\n<h2>4. Optimization and Debugging<\/h2>\n<p>Physical events like collision handling can have a significant impact on performance. Therefore, optimization is necessary. Some optimization methods include:<\/p>\n<ul>\n<li>Removing unnecessary colliders<\/li>\n<li>Setting appropriate Rigidbody settings (Mass, Drag, etc.)<\/li>\n<li>Using the FixedUpdate() method to process physics calculations<\/li>\n<\/ul>\n<h3>4.1 Debugging<\/h3>\n<p>Debugging can help resolve collision issues. If objects are not colliding, you should check the <strong>Is Trigger<\/strong> option and Rigidbody settings. Also, verify if the size and shape of the colliders are correct.<\/p>\n<h2>5. Conclusion<\/h2>\n<p>In this tutorial, we covered object collision handling in Unity in detail. We learned to understand the physics system and how to handle collision and trigger events. This foundational knowledge will serve as an important stepping stone toward creating more advanced games. You can enhance your skills through continuous practice and various projects.<\/p>\n<p>In the next tutorial, we will discuss a more advanced topic, collision responses and physics-based animations. Thank you!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity is a powerful game engine that helps create a variety of games easily. In this tutorial, we will cover the basics of object collision handling in Unity. Collisions are an important element that create interactions between characters, enemies, and items in a game. Therefore, understanding collisions is the first step towards successful game development. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32001\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity basics course: Object collision&#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-32001","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 basics course: Object collision - \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\/32001\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity basics course: Object collision - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Unity is a powerful game engine that helps create a variety of games easily. In this tutorial, we will cover the basics of object collision handling in Unity. Collisions are an important element that create interactions between characters, enemies, and items in a game. Therefore, understanding collisions is the first step towards successful game development. &hellip; \ub354 \ubcf4\uae30 &quot;Unity basics course: Object collision&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32001\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:04:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T12:37:00+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity basics course: Object collision\",\"datePublished\":\"2024-11-01T09:04:50+00:00\",\"dateModified\":\"2024-11-01T12:37:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/\"},\"wordCount\":603,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32001\/\",\"name\":\"Unity basics course: Object collision - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:04:50+00:00\",\"dateModified\":\"2024-11-01T12:37:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32001\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32001\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity basics course: Object collision\"}]},{\"@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 basics course: Object collision - \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\/32001\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity basics course: Object collision - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Unity is a powerful game engine that helps create a variety of games easily. In this tutorial, we will cover the basics of object collision handling in Unity. Collisions are an important element that create interactions between characters, enemies, and items in a game. Therefore, understanding collisions is the first step towards successful game development. &hellip; \ub354 \ubcf4\uae30 \"Unity basics course: Object collision\"","og_url":"https:\/\/atmokpo.com\/w\/32001\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:04:50+00:00","article_modified_time":"2024-11-01T12:37:00+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32001\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32001\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity basics course: Object collision","datePublished":"2024-11-01T09:04:50+00:00","dateModified":"2024-11-01T12:37:00+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32001\/"},"wordCount":603,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32001\/","url":"https:\/\/atmokpo.com\/w\/32001\/","name":"Unity basics course: Object collision - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:04:50+00:00","dateModified":"2024-11-01T12:37:00+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32001\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32001\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32001\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity basics course: Object collision"}]},{"@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\/32001","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=32001"}],"version-history":[{"count":2,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32001\/revisions"}],"predecessor-version":[{"id":38069,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32001\/revisions\/38069"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}