{"id":988,"date":"2026-02-12T22:57:23","date_gmt":"2026-02-12T22:57:23","guid":{"rendered":"https:\/\/sites.wsagames.com\/sz3c23\/?p=988"},"modified":"2026-03-02T01:31:33","modified_gmt":"2026-03-02T01:31:33","slug":"coding-development-player-character","status":"publish","type":"post","link":"https:\/\/sites.wsagames.com\/sz3c23\/coding-development-player-character\/","title":{"rendered":"Coding Development: Player Character"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"988\" class=\"elementor elementor-988\">\n\t\t\t\t<div class=\"elementor-element elementor-element-92b96c9 e-flex e-con-boxed e-con e-parent\" data-id=\"92b96c9\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-7c36f27 elementor-widget elementor-widget-text-editor\" data-id=\"7c36f27\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h4>2D Movement<\/h4><p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-1016\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1.jpg\" alt=\"\" width=\"1558\" height=\"1039\" srcset=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1.jpg 1558w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1-300x200.jpg 300w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1-1024x683.jpg 1024w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1-768x512.jpg 768w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212232725_158_350-1-1536x1024.jpg 1536w\" sizes=\"(max-width: 1558px) 100vw, 1558px\" \/><\/p><p>This script provides <strong>basic WASD player movement<\/strong> using Unity\u2019s 2D physics system.<\/p><p>First, the script requires a <strong>Rigidbody2D component<\/strong>, ensuring that the player object uses <strong>physics-based movement<\/strong>. In Awake(), it retrieves and stores a reference to the Rigidbody2D and sets the player\u2019s <strong>starting position to (0,0,0)<\/strong>.<\/p><p>In Update(), the script <strong>reads horizontal and vertical input<\/strong> using Input.GetAxisRaw(&#8220;Horizontal&#8221;) and Input.GetAxisRaw(&#8220;Vertical&#8221;). These <strong>correspond to the WASD<\/strong> or arrow keys. The input values are stored in a Vector2 called moveInput, and then normalised to prevent diagonal movement from being faster than movement in a single direction.<\/p><p>In FixedUpdate(), the script applies movement by setting the Rigidbody\u2019s velocity to moveInput * moveSpeed. Because this is done in FixedUpdate(), it ensures smooth and consistent physics-based movement.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-0d24731 e-flex e-con-boxed e-con e-parent\" data-id=\"0d24731\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-9f45ef4 elementor-widget elementor-widget-video\" data-id=\"9f45ef4\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;video_type&quot;:&quot;hosted&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"e-hosted-video elementor-wrapper elementor-open-inline\">\n\t\t\t\t\t<video class=\"elementor-video\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/2D-test.mp4\" controls=\"\" preload=\"metadata\" controlsList=\"nodownload\"><\/video>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-64481e3 e-flex e-con-boxed e-con e-parent\" data-id=\"64481e3\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1dbebb5 elementor-widget elementor-widget-text-editor\" data-id=\"1dbebb5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5>\u00a0<\/h5><hr \/><h4>2.5D Movement<\/h4><p>Although our game visually appears 2.5D (a 2D sprite in a 3D environment), the player movement script must be implemented using Unity\u2019s<strong> 3D physics system<\/strong>. I adapted my knowledge of 2D movement scripts and applied it to a 3D setup so that a 2D character sprite could move naturally within a 3D scene.<\/p><p><img decoding=\"async\" class=\"alignnone size-full wp-image-1018\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-scaled.jpg\" alt=\"\" width=\"1440\" height=\"2560\" srcset=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-scaled.jpg 1440w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-169x300.jpg 169w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-576x1024.jpg 576w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-768x1365.jpg 768w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-864x1536.jpg 864w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260212233201_162_350-1152x2048.jpg 1152w\" sizes=\"(max-width: 1440px) 100vw, 1440px\" \/><\/p><p>First, the script reads horizontal and vertical input from the player. It converts it into movement <strong>along the X and Z axes<\/strong>, allowing the character to <strong>move left, right, forward, and backwards within a 3D environment<\/strong>.<\/p><p>The movement vector is normalised to ensure consistent speed in all directions, and the <strong>Rigidbody\u2019s velocity is updated<\/strong> in the physics loop to create physics-based motion.<\/p><p>Since the character uses 3D physics, <strong>all rotation is frozen<\/strong> to prevent it from tipping over when colliding with objects.<\/p><p>The script also handles visual feedback: when the player moves left or right, the sprite is <strong>flipped horizontally by adjusting the SpriteRenderer<\/strong>, and the Animator is updated to switch between idle and running states based on movement input.<\/p><p>Compared to a 2D movement script, the main difference is the use of a 3D Rigidbody and Vector3 instead of Rigidbody2D and Vector2. In 2D, movement typically happens along the X and Y axes, whereas in this 2.5D setup, movement occurs along X and Z, with Y reserved for height. Collision handling and physics behaviour also follow 3D rules.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-f7460b9 e-flex e-con-boxed e-con e-parent\" data-id=\"f7460b9\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e57b271 elementor-widget elementor-widget-video\" data-id=\"e57b271\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;video_type&quot;:&quot;hosted&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"e-hosted-video elementor-wrapper elementor-open-inline\">\n\t\t\t\t\t<video class=\"elementor-video\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/3D-test.mp4\" controls=\"\" preload=\"metadata\" controlsList=\"nodownload\"><\/video>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>2D Movement This script provides basic WASD player movement using Unity\u2019s 2D physics system. First, the script requires a Rigidbody2D component, ensuring that the player object uses physics-based movement. In Awake(), it retrieves and stores a reference to the Rigidbody2D and sets the player\u2019s starting position to (0,0,0). In Update(), the script reads horizontal and [&hellip;]<\/p>\n","protected":false},"author":59,"featured_media":1015,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-988","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":10,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1235,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts\/988\/revisions\/1235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/media\/1015"}],"wp:attachment":[{"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}