{"id":994,"date":"2026-02-12T23:13:34","date_gmt":"2026-02-12T23:13:34","guid":{"rendered":"https:\/\/sites.wsagames.com\/sz3c23\/?p=994"},"modified":"2026-03-02T01:29:00","modified_gmt":"2026-03-02T01:29:00","slug":"coding-development-npc-ai-navigation","status":"publish","type":"post","link":"https:\/\/sites.wsagames.com\/sz3c23\/coding-development-npc-ai-navigation\/","title":{"rendered":"Coding Development: Animal Auto Navigation"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"994\" class=\"elementor elementor-994\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e48acee e-flex e-con-boxed e-con e-parent\" data-id=\"e48acee\" 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-77f042e elementor-widget elementor-widget-text-editor\" data-id=\"77f042e\" 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<p data-start=\"232\" data-end=\"514\">In <em data-start=\"235\" data-end=\"247\">Soulkeeper<\/em>, the core characters of the game are <strong>animals<\/strong>. Because of this, I wanted them to feel alive, natural, and dynamic rather than static objects in the scene. To achieve this, I implemented an <strong>automatic walking system<\/strong> for the animal character, specifically the peacock.<\/p><hr \/><h4 data-start=\"516\" data-end=\"556\">Engine Setup<\/h4><p data-start=\"558\" data-end=\"713\">First, under the <strong data-start=\"575\" data-end=\"585\">Ground<\/strong> layer, I added a <strong data-start=\"603\" data-end=\"622\">NavMesh Surface<\/strong> component. This allows the ground to be baked as a walkable navigation area for AI agents.<\/p><p data-start=\"715\" data-end=\"896\">Next, I selected the peacock object and added a <strong data-start=\"763\" data-end=\"780\">NavMesh Agent<\/strong> component in the Inspector. This component enables the peacock to move intelligently within the baked NavMesh area.<\/p><p data-start=\"898\" data-end=\"1273\">I then opened the <strong data-start=\"916\" data-end=\"937\">Navigation window<\/strong> separately and adjusted the agent\u2019s <strong data-start=\"974\" data-end=\"984\">Radius<\/strong> and <strong data-start=\"989\" data-end=\"999\">Height<\/strong> to appropriate values. These parameters define the peacock\u2019s physical navigation boundaries and collision size. By fine-tuning them, I ensured that the peacock would move naturally within its valid activity range without clipping into obstacles or exceeding walkable areas.<\/p><p data-start=\"898\" data-end=\"1273\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-1137\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732.png\" alt=\"\" width=\"2560\" height=\"1528\" srcset=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732.png 2560w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732-300x179.png 300w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732-1024x611.png 1024w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732-768x458.png 768w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732-1536x917.png 1536w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5c4f\u5e55\u622a\u56fe-2026-02-21-005732-2048x1222.png 2048w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/p><p data-start=\"1275\" data-end=\"1421\">After configuring the NavMesh system, I attached a custom script called <strong data-start=\"1347\" data-end=\"1365\">PeacockNavAuto<\/strong> to control the peacock\u2019s autonomous wandering behaviour.<\/p><p data-start=\"1275\" data-end=\"1421\"><img decoding=\"async\" class=\"alignnone size-full wp-image-1136\" src=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-scaled.jpg\" alt=\"\" width=\"1343\" height=\"2560\" srcset=\"https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-scaled.jpg 1343w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-157x300.jpg 157w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-537x1024.jpg 537w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-768x1464.jpg 768w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-806x1536.jpg 806w, https:\/\/sites.wsagames.com\/sz3c23\/wp-content\/uploads\/sites\/68\/2026\/02\/\u5fae\u4fe1\u56fe\u7247_20260221173916_200_350-1075x2048.jpg 1075w\" sizes=\"(max-width: 1343px) 100vw, 1343px\" \/><\/p><p data-start=\"308\" data-end=\"757\">At the top of the script, I included <code data-start=\"345\" data-end=\"368\">using UnityEngine.AI<\/code> so that I could use Unity\u2019s NavMesh system. The script defines two public variables: <code data-start=\"454\" data-end=\"468\">wanderRadius<\/code> and <code data-start=\"473\" data-end=\"489\">wanderInterval<\/code>. The wanderRadius controls <strong>how far the peacock is allowed to move<\/strong> from its current position, while wanderInterval determines <strong>how often it chooses a new destination<\/strong>. Because they are public, I can easily adjust them in the Inspector to fine-tune the movement behaviour.<\/p><p data-start=\"759\" data-end=\"940\">I then declared a <code data-start=\"777\" data-end=\"791\">NavMeshAgent<\/code> variable to control movement, a <code data-start=\"824\" data-end=\"842\">Transform visual<\/code> variable to control the sprite\u2019s <strong>facing direction<\/strong>, and a <code data-start=\"900\" data-end=\"907\">timer<\/code> to track time between movements.<\/p><p data-start=\"942\" data-end=\"1334\">In the <code data-start=\"949\" data-end=\"958\">Start()<\/code> method, the script gets the NavMeshAgent component attached to the peacock and finds the SpriteRenderer in its children. I disabled automatic rotation and vertical axis updates because this is a <strong>2D character<\/strong>, and I don\u2019t want Unity\u2019s 3D rotation system to affect it.<\/p><p data-start=\"1336\" data-end=\"1609\">In the <code data-start=\"1343\" data-end=\"1353\">Update()<\/code> method, a timer increases every frame. When the peacock reaches its destination or when the set time interval has passed, it chooses a new random position to walk toward. This keeps the movement feeling <strong>natural and continuous<\/strong>.<\/p><p data-start=\"1611\" data-end=\"1957\">The <code data-start=\"1615\" data-end=\"1636\">SetNewDestination()<\/code> function generates a random point within a certain radius around the peacock. It then uses <code data-start=\"1728\" data-end=\"1754\">NavMesh.SamplePosition()<\/code> to make sure that the chosen position is actually <strong>on a walkable NavMesh area<\/strong>. If the position is valid, the agent moves toward that target. This creates a smooth wandering effect within a limited range.<\/p><p data-start=\"1959\" data-end=\"2231\">The <code data-start=\"1972\" data-end=\"1990\">FlipByVelocity()<\/code> function makes the peacock <strong>face the direction it is moving<\/strong>. If the velocity on the X-axis is positive, the sprite faces right; if it is negative, the sprite faces left.<\/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-02413e0 e-flex e-con-boxed e-con e-parent\" data-id=\"02413e0\" 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-08bc1b3 elementor-widget elementor-widget-video\" data-id=\"08bc1b3\" 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\/Peacock-Navigation.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>In Soulkeeper, the core characters of the game are animals. Because of this, I wanted them to feel alive, natural, and dynamic rather than static objects in the scene. To achieve this, I implemented an automatic walking system for the animal character, specifically the peacock. Engine Setup First, under the Ground layer, I added a [&hellip;]<\/p>\n","protected":false},"author":59,"featured_media":1121,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-994","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\/994","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=994"}],"version-history":[{"count":11,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":1226,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/posts\/994\/revisions\/1226"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/media\/1121"}],"wp:attachment":[{"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wsagames.com\/sz3c23\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}