{"id":219,"date":"2026-10-03T11:01:43","date_gmt":"2026-10-03T09:01:43","guid":{"rendered":"https:\/\/www.noocturnalgamesstudio.com\/blog\/2026\/10\/03\/evolving-npcs-creating-ais-that-loot-items-and-improve-stats-in-unity\/"},"modified":"2026-10-03T11:01:43","modified_gmt":"2026-10-03T09:01:43","slug":"evolving-npcs-creating-ais-that-loot-items-and-improve-stats-in-unity","status":"publish","type":"post","link":"https:\/\/www.noocturnalgamesstudio.com\/blog\/2026\/10\/03\/evolving-npcs-creating-ais-that-loot-items-and-improve-stats-in-unity\/","title":{"rendered":"Evolving NPCs: Creating AIs that Loot Items and Improve Stats in Unity"},"content":{"rendered":"<div style='font-family: system-ui, -apple-system, sans-serif; line-height: 1.8; color: #e2e8f0; font-size: 16px;'>\n<p style='margin-bottom: 15px;'> Have you ever felt that your game enemies are just static punching bags waiting to be hit? In indie development, the difference between a mediocre game and a memorable one lies in world reactivity. If an NPC sees a better sword on the ground, why would they ignore it? <\/p>\n<p style='margin-bottom: 15px;'> Today we are diving deep into how to use the <strong>Modular AI Behaviour Kit<\/strong> to create a dynamic looting system where your AIs do not just patrol\u2014they evolve by collecting items and improving their stats in real-time. <\/p>\n<hr style='border: 0; border-top: 1px solid #4a5568; margin: 30px 0;'>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> 1. The Philosophy of Modular Composition <\/h3>\n<p style='margin-bottom: 15px;'> Most developers try to program a monolithic AI with thousands of lines of code. With our Kit, we change that approach to <strong>Personality by Composition<\/strong>. To make an NPC pick up items, we only need to combine three basic senses: <\/p>\n<ul style='color: #cbd5e0; margin-bottom: 15px;'>\n<li><strong>PlayerDetector (reconfigured):<\/strong> To detect objects in a specific layer (&#8216;Loot&#8217;).<\/li>\n<li><strong>SimpleChase:<\/strong> To drive the NPC toward the detected object.<\/li>\n<li><strong>AIController:<\/strong> To manage the transition between &#8216;Patrol&#8217; and &#8216;Looting&#8217;.<\/li>\n<\/ul>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> 2. Setting Up Object Perception <\/h3>\n<p style='margin-bottom: 15px;'> The <code>PlayerDetector<\/code> component is extremely versatile. Although its name suggests it only detects players, it works with any <code>LayerMask<\/code>. To create a scavenger NPC, we set up a second detector on the same GameObject: <\/p>\n<div style='background-color: rgba(255, 255, 255, 0.05); border-left: 3px solid #f687b3; padding: 15px; margin-bottom: 20px; border-radius: 0 8px 8px 0;'> <strong>Pro Tip:<\/strong> Create a layer named &#8216;Loot&#8217;. In the NPC inspector, assign this layer to the &#8216;Target Layer&#8217; field of a new PlayerDetector. Your AI now has &#8216;eyes&#8217; for loot. <\/div>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> 3. The Brain: Managing the Looting State <\/h3>\n<p style='margin-bottom: 15px;'> The <code>AIController<\/code> acts as the conductor. When the loot detector fires the <code>OnTargetDetected<\/code> event, the controller must pause the patrol and activate the chase toward the item. <\/p>\n<p> <code style='display:block; background: #1a202c; color: #68d391; padding: 10px; border-radius: 5px; margin: 5px 0; font-family: monospace; border: 1px solid #2d3748;'> \/\/ Logic example in the AIController <br \/> _lootDetector.OnTargetDetected.AddListener((lootItem) => { <br \/> &nbsp;&nbsp;ChangeState(AIState.Chasing); <br \/> &nbsp;&nbsp;_chase.ManualStartChase(lootItem); <br \/> }); <\/code> <\/p>\n<h4 style='color: #fff; margin-top: 30px; font-weight: 600;'> 4. Stat Evolution (MAS Integration) <\/h4>\n<p style='margin-bottom: 15px;'> Picking up the object is only half the battle. The real magic happens when the NPC improves. This is where <strong>Modular Attributes &#038; Stats (MAS)<\/strong> comes into play. Upon reaching the item, we trigger an event that applies an <code>AttributeModifier<\/code> to the NPC. <\/p>\n<div style='background-color: rgba(255, 255, 255, 0.05); border-left: 3px solid #f687b3; padding: 15px; margin-bottom: 20px; border-radius: 0 8px 8px 0;'> If the NPC picks up a &#8216;Strength Potion&#8217;, the MAS system automatically adds a +5 modifier to the &#8216;Strength&#8217; attribute. This instantly recalculates their attack damage without additional scripts. <\/div>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> Conclusion <\/h3>\n<p style='margin-bottom: 15px;'> Creating believable AIs does not have to be a technical nightmare. By using an event-based modular approach, you allow your NPCs to interact with the environment organically. The <strong>Modular AI Behaviour Kit<\/strong> gives you the muscles and the senses; you just have to define the ambition of your creatures. <\/p>\n<div style='background: linear-gradient(145deg, #1a202c, #2d3748); border: 1px solid #4a5568; padding: 25px; border-radius: 12px; margin-top: 40px; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.3);'>\n<p style='margin-bottom: 10px; font-weight: bold; color: #fff; font-size: 1.1em;'>Level up your game today<\/p>\n<p style='margin-bottom: 0; color: #cbd5e0;'>Get this asset on the <a href='#' style='color: #39FF14; text-decoration: underline; font-weight: bold;'>Unity Asset Store<\/a>.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever felt that your game enemies are just static punching bags waiting to be hit? In indie development, the difference between a mediocre game and a memorable one lies in world reactivity. If an NPC sees a better sword on the ground, why would they ignore it? Today we are diving deep into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-sin-categoria"],"_links":{"self":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}