{"id":32011,"date":"2024-11-01T09:04:55","date_gmt":"2024-11-01T09:04:55","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32011"},"modified":"2024-11-01T11:33:42","modified_gmt":"2024-11-01T11:33:42","slug":"unity-basics-course-first-person-view-and-rotation-function","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32011\/","title":{"rendered":"Unity Basics Course: First-Person View and Rotation Function"},"content":{"rendered":"<p><body><\/p>\n<article>\n<header>\n<p>Unity is a powerful engine that innovatively changes many aspects of modern game development. In this course, we will explain in detail how to implement a first-person perspective and add a rotation feature within that perspective. This will provide an opportunity to create your first gameplay experience in Unity.<\/p>\n<\/header>\n<section>\n<h2>1. Installing Unity and Basic Setup<\/h2>\n<p>To use Unity, you must first download and install the Unity Hub from the official website. After installation, create a new project and select the &#8220;3D&#8221; template. The 3D template is suitable for creating perspective-based games like first-person views.<\/p>\n<\/section>\n<section>\n<h2>2. Setting Up the First-Person Character Controller<\/h2>\n<p>To implement a first-person game in Unity, you need to set up a character controller. This allows the player to explore the game environment. Proceed to the next steps.<\/p>\n<h3>2.1 Adding the Character Controller<\/h3>\n<p>Right-click in the Hierarchy window of the project and select &#8220;3D Object&#8221; &gt; &#8220;Capsule&#8221; to create a capsule. This will be used as the player. Rename the capsule to &#8216;Player&#8217;.<\/p>\n<h3>2.2 Adding a Camera<\/h3>\n<p>To create an actual first-person view, you need to add a camera on top of the capsule. Select the Player object, right-click, and choose &#8220;Camera&#8221; to add the camera. The camera should be placed as a child of the Capsule object.<\/p>\n<h3>2.3 Adjusting Camera Position<\/h3>\n<p>Adjust the camera&#8217;s position to match the player&#8217;s head height. Generally, set the Y-axis value to 1.5. Use the Transform component to adjust the camera&#8217;s position.<\/p>\n<\/section>\n<section>\n<h2>3. Implementing Rotation Functionality<\/h2>\n<p>Now let&#8217;s add the rotation functionality so the player can adjust the view direction. To do this, you need to write a C# script.<\/p>\n<h3>3.1 Creating a New Script<\/h3>\n<p>Right-click in the Project window and select \u201cCreate\u201d &gt; \u201cC# Script\u201d to create a new script and name it &#8220;PlayerController&#8221;. Drag this script onto the Player object to add it.<\/p>\n<h3>3.2 Writing the Script Content<\/h3>\n<p>Open the PlayerController script and write the following code to implement the player&#8217;s movement and rotation features:<\/p>\n<pre>\n<code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class PlayerController : MonoBehaviour\n{\n    public float speed = 5.0f;\n    public float sensitivity = 2.0f;\n\n    private float rotationY = 0.0f;\n\n    void Update()\n    {\n        \/\/ Rotation\n        float mouseX = Input.GetAxis(\"Mouse X\") * sensitivity;\n        float mouseY = Input.GetAxis(\"Mouse Y\") * sensitivity;\n\n        rotationY -= mouseY;\n        rotationY = Mathf.Clamp(rotationY, -90f, 90f); \/\/ Limiting view\n\n        Camera.main.transform.localRotation = Quaternion.Euler(rotationY, 0, 0);\n        transform.Rotate(Vector3.up * mouseX);\n\n        \/\/ Movement\n        float moveX = Input.GetAxis(\"Horizontal\");\n        float moveZ = Input.GetAxis(\"Vertical\");\n        Vector3 move = transform.right * moveX + transform.forward * moveZ;\n        CharacterController controller = GetComponent<CharacterController>();\n        controller.Move(move * speed * Time.deltaTime);\n    }\n}\n<\/CharacterController><\/code>\n            <\/pre>\n<h3>3.3 Explanation of the Script<\/h3>\n<p>The above code implements the following functionalities:<\/p>\n<ul>\n<li><strong>Mouse Input:<\/strong> Calculates rotation based on mouse movement.<\/li>\n<li><strong>Vertical and Horizontal Input:<\/strong> Adjusts the player&#8217;s position through WASD key input.<\/li>\n<li><strong>CharacterController:<\/strong> Uses Unity&#8217;s CharacterController for physical collision handling while moving.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>4. Physics Settings and Improvements<\/h2>\n<p>Now that the basic first-person player controller is complete, let&#8217;s address a few improvements and physics settings.<\/p>\n<h3>4.1 Adjusting Gravity<\/h3>\n<p>You need to add gravity using the CharacterController. Add gravity and jump functionality in the PlayerController script:<\/p>\n<pre>\n<code>private Vector3 velocity;\n\nvoid Update()\n{\n    ...\n    \/\/ Adding gravity\n    if (controller.isGrounded)\n    {\n        velocity.y = -0.5f;\n    }\n    else\n    {\n        velocity.y += Physics.gravity.y * Time.deltaTime;\n    }\n    controller.Move(velocity * Time.deltaTime);\n}\n<\/code>\n            <\/pre>\n<h3>4.2 Adding Jump Functionality<\/h3>\n<p>To implement jumping, you should detect space key input so that the player can jump. Add the following code.<\/p>\n<pre>\n<code>if (Input.GetButtonDown(\"Jump\") && controller.isGrounded)\n{\n    velocity.y = Mathf.Sqrt(jumpHeight * -2f * Physics.gravity.y);\n}\n<\/code>\n            <\/pre>\n<h3>4.3 Visual Improvements<\/h3>\n<p>To create a more natural camera perspective, it&#8217;s a good idea to add animations for when the player moves. Consider using Animator and Animation Clip for this purpose.<\/p>\n<\/section>\n<section>\n<h2>5. Additions and Optimization<\/h2>\n<p>To enhance the player&#8217;s sensory experience, consider the following additions.<\/p>\n<h3>5.1 Adding Sound Effects<\/h3>\n<p>Adding sounds for movement and jumping can increase immersion. Learn how to add sounds using the AudioSource component.<\/p>\n<h3>5.2 Using Canvas for Interface and HUD Configuration<\/h3>\n<p>Add a UI Canvas to provide essential information to the player. The HUD can display health, mini-maps, scores, etc.<\/p>\n<h3>5.3 Optimization<\/h3>\n<p>To prevent performance degradation of assets or scripts, analyze and optimize performance using the Profiler. Monitor Unity&#8217;s memory usage and CPU usage to adjust to optimal conditions.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>Through this course, we have learned about the basic implementation of a first-person perspective and rotation functionality in Unity. Based on this foundational knowledge, try using your creativity to create various games.<\/p>\n<p>Unity is a platform with endless possibilities. Enhance your abilities in Unity through practice and experimentation. We will learn about various features and advanced game development processes in future courses. Happy developing!<\/p>\n<\/section>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity is a powerful engine that innovatively changes many aspects of modern game development. In this course, we will explain in detail how to implement a first-person perspective and add a rotation feature within that perspective. This will provide an opportunity to create your first gameplay experience in Unity. 1. Installing Unity and Basic Setup &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32011\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: First-Person View and Rotation Function&#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-32011","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: First-Person View and Rotation Function - \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\/32011\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: First-Person View and Rotation Function - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Unity is a powerful engine that innovatively changes many aspects of modern game development. In this course, we will explain in detail how to implement a first-person perspective and add a rotation feature within that perspective. This will provide an opportunity to create your first gameplay experience in Unity. 1. Installing Unity and Basic Setup &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: First-Person View and Rotation Function&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32011\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:04:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:42+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\/32011\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32011\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: First-Person View and Rotation Function\",\"datePublished\":\"2024-11-01T09:04:55+00:00\",\"dateModified\":\"2024-11-01T11:33:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32011\/\"},\"wordCount\":621,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32011\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32011\/\",\"name\":\"Unity Basics Course: First-Person View and Rotation Function - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:04:55+00:00\",\"dateModified\":\"2024-11-01T11:33:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32011\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32011\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32011\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: First-Person View and Rotation Function\"}]},{\"@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: First-Person View and Rotation Function - \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\/32011\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: First-Person View and Rotation Function - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Unity is a powerful engine that innovatively changes many aspects of modern game development. In this course, we will explain in detail how to implement a first-person perspective and add a rotation feature within that perspective. This will provide an opportunity to create your first gameplay experience in Unity. 1. Installing Unity and Basic Setup &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: First-Person View and Rotation Function\"","og_url":"https:\/\/atmokpo.com\/w\/32011\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:04:55+00:00","article_modified_time":"2024-11-01T11:33:42+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\/32011\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32011\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: First-Person View and Rotation Function","datePublished":"2024-11-01T09:04:55+00:00","dateModified":"2024-11-01T11:33:42+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32011\/"},"wordCount":621,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32011\/","url":"https:\/\/atmokpo.com\/w\/32011\/","name":"Unity Basics Course: First-Person View and Rotation Function - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:04:55+00:00","dateModified":"2024-11-01T11:33:42+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32011\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32011\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32011\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: First-Person View and Rotation Function"}]},{"@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\/32011","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=32011"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32011\/revisions"}],"predecessor-version":[{"id":32012,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32011\/revisions\/32012"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}