{"id":91,"date":"2026-04-04T11:01:21","date_gmt":"2026-04-04T09:01:21","guid":{"rendered":"https:\/\/www.noocturnalgamesstudio.com\/blog\/2026\/04\/04\/ia-dinamica-y-contextual-en-unity-como-tu-npc-priorizara-huir-perseguir-o-investigar-sonidos-sin-un-if-else-gigante\/"},"modified":"2026-04-04T11:01:21","modified_gmt":"2026-04-04T09:01:21","slug":"ia-dinamica-y-contextual-en-unity-como-tu-npc-priorizara-huir-perseguir-o-investigar-sonidos-sin-un-if-else-gigante","status":"publish","type":"post","link":"https:\/\/www.noocturnalgamesstudio.com\/blog\/2026\/04\/04\/ia-dinamica-y-contextual-en-unity-como-tu-npc-priorizara-huir-perseguir-o-investigar-sonidos-sin-un-if-else-gigante\/","title":{"rendered":"IA Din\u00e1mica y Contextual en Unity: C\u00f3mo tu NPC priorizar\u00e1 Huir, Perseguir o Investigar Sonidos (sin un IF\/ELSE gigante)"},"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;'> Si eres un desarrollador indie, conoces este sentimiento: abres tu script de IA y te encuentras con un monstruo de 500 l\u00edneas lleno de condiciones anidadas. &#8216;Si el jugador est\u00e1 cerca, pero mi vida es baja, corre; pero si escucho un ruido y no veo a nadie, investiga; pero si un aliado grita&#8230;&#8217;. <\/p>\n<p style='margin-bottom: 15px;'> El resultado es un c\u00f3digo fr\u00e1gil, dif\u00edcil de depurar y NPCs que se comportan de forma err\u00e1tica. \u00bfLa soluci\u00f3n? Dejar de programar estados y empezar a componer comportamientos. Hoy vamos a desglosar c\u00f3mo la arquitectura event-driven del <strong>Modular AI Behaviour Kit<\/strong> transforma este caos en un sistema profesional y escalable. <\/p>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> El Fin del Espagueti: Arquitectura Basada en Eventos <\/h3>\n<p style='margin-bottom: 15px;'> La mayor\u00eda de los tutoriales de Unity te ense\u00f1an a usar el m\u00e9todo Update() para comprobar distancias en cada frame. Es ineficiente. Nuestro kit utiliza <strong>UnityEvents<\/strong>. Los componentes de &#8216;sentidos&#8217; (como el PlayerDetector) emiten eventos solo cuando algo cambia. <\/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;'>\n<h4 style='color: #fff; margin-top: 0; font-weight: 600;'> Ejemplo Pr\u00e1ctico: <\/h4>\n<p style='margin-bottom: 0;'> El componente <strong>SimpleChase<\/strong> no busca al jugador. Se suscribe al evento <em>OnTargetDetected<\/em> del <strong>PlayerDetector<\/strong>. En el momento en que el raycast visual confirma la l\u00ednea de visi\u00f3n, la persecuci\u00f3n comienza instant\u00e1neamente. Sin comprobaciones innecesarias en cada frame. <\/p>\n<\/p><\/div>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> Priorizaci\u00f3n Inteligente: El Cerebro Coordinador <\/h3>\n<p style='margin-bottom: 15px;'> \u00bfC\u00f3mo decide un NPC qu\u00e9 hacer cuando ocurren dos cosas a la vez? Aqu\u00ed entra el <strong>AIController<\/strong>. Este script act\u00faa como un director de orquesta que gestiona una M\u00e1quina de Estados Finitos (FSM) basada en la composici\u00f3n de Addons. <\/p>\n<p style='margin-bottom: 15px;'> La jerarqu\u00eda de decisiones est\u00e1 integrada en la l\u00f3gica del controlador: <\/p>\n<ul style='color: #cbd5e0; margin-bottom: 15px;'>\n<li><strong>P\u00e1nico (Huir):<\/strong> Si el NPC tiene un <em>FleeBehavior<\/em>, el controlador le da prioridad absoluta sobre el combate. Ideal para civiles o animales.<\/li>\n<li><strong>Agresi\u00f3n (Perseguir):<\/strong> Si no hay miedo pero s\u00ed un objetivo detectado, activa el <em>SimpleChase<\/em> y los m\u00f3dulos de ataque (Melee o Ranged).<\/li>\n<li><strong>Curiosidad (Investigar):<\/strong> Si el <em>SoundReceiver<\/em> detecta un ruido mientras el NPC patrulla, el controlador transiciona al estado <em>Searching<\/em> para ir a la \u00faltima posici\u00f3n del sonido.<\/li>\n<\/ul>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> Creando Personalidades en Segundos <\/h3>\n<p style='margin-bottom: 15px;'> Con el Modular AI Behaviour Kit, la &#8216;personalidad&#8217; de tu enemigo no se programa, se ensambla. Mira estos arquetipos: <\/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;'> \/\/ El Zombi de Horda: <br \/> PlayerDetector + SimpleChase + MeleeAttack + Alerter <\/p>\n<p> \/\/ El Arquero T\u00e1ctico: <br \/> PlayerDetector + SimpleChase (con Minimum Distance) + RangedAttack + SearchBehavior <\/code> <\/p>\n<p style='margin-bottom: 15px;'> Al a\u00f1adir el componente <strong>Alerter<\/strong>, un zombi que detecta al jugador &#8216;gritar\u00e1&#8217; (emitir\u00e1 una alerta social), activando a todos los NPCs cercanos que tengan un <strong>AlertReceiver<\/strong>, incluso si ellos a\u00fan no han visto al jugador. Esto crea comportamientos de grupo realistas de forma autom\u00e1tica. <\/p>\n<h3 style='color: #39FF14; margin-top: 30px; font-weight: 700; letter-spacing: 0.5px;'> Conclusi\u00f3n: Modulariad es Poder <\/h3>\n<p style='margin-bottom: 15px;'> No pierdas meses reinventando la rueda de la IA. Al separar la percepci\u00f3n (sentidos) de la ejecuci\u00f3n (movimiento y ataque), obtienes un sistema que puedes extender y reutilizar en cualquier proyecto, desde un survival horror hasta un RPG t\u00e1ctico. <\/p>\n<hr style='border: 0; border-top: 1px solid #4a5568; margin: 30px 0;'>\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;'>Mejora tu juego hoy<\/p>\n<p style='margin-bottom: 0; color: #cbd5e0;'>Consigue este asset en la <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>Si eres un desarrollador indie, conoces este sentimiento: abres tu script de IA y te encuentras con un monstruo de 500 l\u00edneas lleno de condiciones anidadas. &#8216;Si el jugador est\u00e1 cerca, pero mi vida es baja, corre; pero si escucho un ruido y no veo a nadie, investiga; pero si un aliado grita&#8230;&#8217;. El resultado [&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-91","post","type-post","status-publish","format-standard","hentry","category-sin-categoria"],"_links":{"self":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/posts\/91","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=91"}],"version-history":[{"count":0,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.noocturnalgamesstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}