- 作者
- Joe
- 译者
- Ethanz0x0
- 转载许可
- 允许转载,按照 CC BY-NC-SA 4.0 协议进行授权,转载本帖时须注明平台名称(GHytale)以及本帖地址
NPC Technical Rundown NPC 技术概述
Hello everyone! This post is going to briefly cover some topics relating to Hytale's NPC framework, its current state, how it looks, and where we want to take it. Some of the content might be a bit more technical, so feel free to skip through or skim the parts that don't interest you. There's also a lot to cover when it comes to NPC-related systems, so don't expect this one post to be exhaustive!
大家好!这篇文章将简要介绍 Hytale 的 NPC 框架,包括其现状、外观以及未来的发展方向。部分内容可能比较技术性,您可以跳过或略读不感兴趣的部分。NPC 相关系统涉及的内容很多,所以这篇文章不可能面面俱到!
Where we are 我们在干什么
As it stands, the NPC framework supports a wide variety of behaviours across multiple systems, all of which are configurable using data-driven assets. You don't need to know any programming languages to be able to set them up - even our most complex NPCs are almost entirely data-driven.目前,NPC 框架支持跨多个系统的多种行为,所有这些行为都可以通过数据驱动的资源进行配置。您无需掌握任何编程语言即可进行设置——即使是我们最复杂的 NPC 也几乎完全由数据驱动。
We achieve this through a number of different behaviour-related systems, but the two we'll cover in this post are 'Roles' (the heart of our NPCs) and the 'Combat Action Evaluator'.
我们通过许多不同的行为相关系统来实现这一点,但本文将介绍的两个系统是“角色”(我们 NPC 的核心)和“战斗行动评估器”。
Documentation and Tutorial 文档和教程
If you want to learn more about NPCs, our friends at hytalemodding have a lot of great documentation already and we provided the generated NPC one as well as a written tutorial.如果您想了解更多关于 NPC 的信息,我们的朋友 hytalemodding 已经有很多很棒的文档,我们也提供了生成的 NPC 文档以及书面教程 。
Together with this tutorial we made a 6 part video series, where we cover some parts of it in extra detail; for the best experience use both:
配合本教程,我们制作了一个共 6 集的视频系列,其中对部分内容进行了更详细的讲解;为了获得最佳体验,请同时观看两者:
Roles 角色
Every NPC has a role. This is the expression of their general behaviour and how they'll react to different stimuli in the world. Changing an NPC's entire behaviour set is as simple as changing its role, and we provide a number of templates with customizable values that can be applied to make creating new NPCs quick and efficient.每个 NPC 都有自己的角色。这体现了他们的总体行为模式以及他们对世界中不同刺激的反应方式。改变 NPC 的整个行为模式与改变其角色一样简单,我们提供了一系列带有可自定义值的模板,方便您快速高效地创建新的 NPC。
In addition to the behaviour itself, the Role also dictates aspects such as how an NPC will move, what items it carries, what it looks like, and so on.
除了行为本身,角色还决定了 NPC 的移动方式、携带的物品、外观等等方面。
On the technical side, this behaviour is represented by a concept we refer to as 'instruction lists'. This isn't too far removed from decision trees or behaviour trees, but with some of the semantics simplified. Each instruction is made up of a 'sensor' - an element that queries the state of the game to decide if this instruction can be executed - as well as the actions or motions the NPC should take if this instruction is selected. Alternatively, the actions and motions can be replaced by a nested instruction list, giving rise to more intricately constructable behaviours.
从技术层面来说,这种行为可以用我们称之为“指令列表”的概念来表示。它与决策树或行为树的概念并非完全不同,只是在某些语义上进行了简化。每条指令都由一个“传感器”和 NPC 在指令被选中时应该采取的动作或移动组成。传感器会查询游戏状态,以判断该指令是否可以执行。此外,这些动作和移动也可以用嵌套的指令列表来代替,从而构建出更加复杂的行为。
If you're familiar with behaviour trees, you might wonder where the actual differences lie - sensors are somewhat analogous to decorators and it's still a tree-like structure. The key is in the semantics we use for traversing our instruction lists. Where behaviour trees may follow different semantics depending on the node type, we always follow the semantics of the fallback selector node. Each instruction is evaluated in order and - if matched - executed. Unless specific flags are included in the instruction, we won't evaluate any further instructions in the list. This ensures that the flow of logic within the NPC is easy to follow, no matter how large or deep the trees grow.
如果您熟悉行为树,可能会好奇传感器和装饰器之间的真正区别在哪里——传感器在某种程度上类似于装饰器,而且它们也都是树状结构。关键在于我们遍历指令列表时使用的语义。行为树可能根据节点类型遵循不同的语义,而我们始终遵循回退选择器节点的语义 。每条指令都会按顺序进行评估,如果匹配则执行。除非指令中包含特定的标志,否则我们不会评估列表中的任何其他指令。这确保了无论树状结构多么庞大或深邃,NPC 内部的逻辑流程都易于理解。
While all the individual element types (sensors, actions, motions, etc) are written in Java, the instruction lists are constructed entirely in JSON. At this stage we have more than 150 different element types that can be combined to build behaviours and a framework in place to make it easy for modders to add more with Java. Not all of them are in a finished state, but we're actively working to iterate on them and add as many more as we can!
虽然所有元素类型(传感器、动作、运动等)都是用 Java 编写的,但指令列表完全是用 JSON 构建的。目前,我们拥有超过 150 种不同的元素类型,可以组合起来构建各种行为,并且已经搭建了一个框架,方便模组制作者使用 Java 添加更多元素。并非所有元素类型都已完成,但我们正在积极迭代,并尽可能多地添加新的元素!
At its core, we designed our NPC framework to be interacted with on several different levels. Whether you're completely new to modding and NPC design or a veteran able to craft complex behaviours, we want to ensure there are ways for everyone to be able to bring their creations to life.
从本质上讲,我们的 NPC 框架设计旨在实现多层次的互动。无论您是模组和 NPC 设计的新手,还是能够打造复杂行为的资深玩家,我们都希望确保每个人都能找到方法,将自己的作品变为现实。
Here is an example of changing the Sheep role to go from a Livestock behavior enabled by Template_Animal_Neutral to being aggressive with the help of Template_Predator.
以下是一个将绵羊角色从 Template_Animal_Neutral 启用的牲畜行为更改为 Template_Predator 启用的攻击性行为的示例。
And it goes from being fond of you to attacking.
这种转变从喜欢你到攻击你。
With some basic templates we created, you can also give it a random Weapon and you are ready for Die Hard Sheep mod
我们创建了一些基本模板,你可以给它随机分配武器,这样就可以开始玩 Die Hard Sheep 模组了。
The Combat Action Evaluator 战斗行动评估器
Though instruction lists already give designers a great deal of flexibility to configure their NPCs and implement combat behaviours, crafting a character that does more than few basic attacks and needs to make some sort of decision about when to use certain attacks quickly becomes cumbersome.虽然指令列表已经为设计师提供了很大的灵活性来配置他们的 NPC 并实现战斗行为,但是要创建一个进行多次基本攻击并且需要决定何时使用某些攻击的角色,很快就会变得很麻烦。
The combat action evaluator exists to address these needs, by offering a companion framework to an NPCs central behaviour that can make smart moment-to-moment decisions about its state, the state of the world around it, and its enemies or allies. Each possible attack (or other combat action) is assigned a set of conditions that designate the best time to use it - when HP is low; when the enemy is close; when a player is trying to sneak around the back. These conditions are then evaluated and each action is weighed against the others to determine the course of action the NPC wants to take.
战斗行动评估器旨在满足这些需求,它为 NPC 的核心行为提供了一个辅助框架,使其能够根据自身状态、周围环境以及敌友情况做出明智的实时决策。每一种可能的攻击(或其他战斗行动)都对应着一系列条件,这些条件决定了最佳使用时机——例如生命值较低时、敌人靠近时、玩家试图绕到背后时等等。评估器会对这些条件进行评估,并将每项行动与其他行动进行比较,从而确定 NPC 想要采取的行动方案。
Making decisions this way introduces a level of 'fuzziness' to the NPC and leads to more interesting combat encounters with less verbose configurations. The downside is that there's a steeper learning curve and NPCs might not always act the way you expect! It's also not as performant, but that's something we hope to improve with further iteration.
这种决策方式为 NPC 引入了一定程度的“模糊性”,从而带来更有趣的战斗体验,同时减少了繁琐的配置。缺点是学习曲线更陡峭,而且 NPC 的行为可能并非总是如你所愿!此外,它的性能也略逊一筹,但我们希望通过后续迭代来改进这一点。
For example, the Skeleton Praetorian can decide between using different abilities with some degree of intelligence: blocking, summoning at low health, and charging, alongside basic attacks.
例如,骷髅禁卫军可以运用一定程度的智能来决定使用不同的技能:格挡、低生命值时召唤、冲锋,以及进行普通攻击。
Below is a snippet that shows part of the configuration for the summon ability condition:
下面这段代码片段展示了召唤能力条件的部分配置:
And here is a video example of those decisions:
以下是这些决策的一个视频示例:
The reality check 现实检验
This all sounds pretty far along, right? Maybe you could even believe it was shippable?这一切听起来进展相当顺利,对吧?你甚至可以认为它已经可以推出了?
Well…no. There are still very many rough edges, missing features, and areas in need of vast improvement. Just as we talked about what the systems can do, it's important that we talk about some of the major areas where we're not quite there yet.
嗯……不。目前仍存在许多不足之处,功能缺失,还有很多方面需要大幅改进。正如我们之前讨论过系统的功能一样,我们也必须谈谈目前尚未完全实现的一些主要领域。
With great power comes…the need for great tooling. We're very far off the mark here. There are plans for visual editing and debugging, but right now most NPC configuration is done directly in JSON files using text editors. It's workable, but painful, and though we provide a variety of avenues for debugging NPCs when they don't work as expected, none of them are intuitive and most require reading through pages upon pages of detailed log files.
强大的力量也意味着更强大的工具。我们在这方面还远远落后。虽然我们计划加入可视化编辑和调试功能,但目前大多数 NPC 配置都是直接在 JSON 文件中使用文本编辑器完成的。这种方式虽然可行,但非常繁琐。尽管我们提供了多种调试 NPC 故障的方法,但这些方法都不够直观,而且大多数都需要阅读大量详细的日志文件。
We mentioned the learning curve associated with the combat action evaluator, but that applies pretty much everywhere when it comes to working with NPCs as well. We envision an easier and smoother onboarding into NPC modding, but at this stage we can only offer a limited number of templates as examples along with documentation on available elements and simple tutorials.
我们之前提到过战斗动作评估器的学习曲线,但这种情况几乎适用于所有与 NPC 相关的操作。我们设想让 NPC 模组的入门流程更加便捷顺畅,但目前我们只能提供数量有限的模板作为示例,以及关于可用元素的文档和简单的教程。
There are plenty of major missing features as well. NPCs don't position themselves very well in combat; they don't use proper avoidance or flocking; while flying NPCs can land and take off, swimming NPCs can't leave the water and vice versa. There's no end to the list of features we still need to add to be able to deliver the game we envision.
此外,还有许多重要功能缺失。NPC 在战斗中站位不佳;他们不会进行有效的躲避或集群行动;飞行 NPC 可以起降,而游泳 NPC 却无法离开水面,反之亦然。为了实现我们设想的游戏,我们需要添加的功能还有很多。
Naturally, the potential for performance issues abounds. We can support a relatively large number of NPCs but there's much work to be done in making them more performant, particularly when it comes to pathfinding. We keep the pathfinder off as much as we can otherwise performance is likely to tank!
当然,性能问题的可能性也很大。我们可以支持相对较多的 NPC,但要提升它们的性能,尤其是在寻路方面,还有很多工作要做。我们会尽可能地关闭寻路器,否则性能很可能会大幅下降!
And then there's all the technical debt that needs to be solved, from NPCs not being able to deliberately break blocks outside of projectile-based explosions due to certain non-NPC system constraints that need to be revised (they can place them though!), to NPC physics needing a complete rework to unify it properly with player systems. There's a long road ahead to get things into proper shape - and we didn't even talk about spawning!
此外,还有一大堆技术债务亟待解决,比如 NPC 由于某些非 NPC 系统的限制(这些限制需要修改),无法在非投射物爆炸的情况下主动破坏方块(但他们可以放置方块!),以及 NPC 物理引擎需要彻底重做才能与玩家系统完美融合。要让一切步入正轨,还有很长的路要走——而且我们甚至还没讨论生成机制呢!
Bugs, bugs everywhere 到处都是Bug
Many community members have pointed out the plethora of bugs that cropped up in released gameplay footage. With our current development pace, much of that footage is already outdated and the most critical of those bugs have already been fixed! However, I do specifically want to take a moment to talk a bit more about pathfinding, its challenges, and what this is likely to mean for release.许多社区成员都指出,已发布的实机演示视频中存在大量漏洞。以我们目前的开发进度来看,很多视频素材已经过时,其中最严重的漏洞也已经修复!不过,我还是想花点时间详细谈谈寻路机制、它面临的挑战,以及这可能对最终版本发布产生的影响。
Pathfinding is a large and complex topic - complex enough that many regular games struggle with it. When you add a procedural fully-modifiable block-based world to the mix, this becomes even more complex since we can no longer rely on many of the tricks games use to optimize performance around known terrain.
寻路是一个庞大而复杂的主题——复杂到许多普通游戏都难以应对。而当涉及到程序生成的、完全可修改的基于方块的世界时,情况就变得更加复杂了,因为我们无法再依赖游戏中那些用来优化已知地形性能的技巧。
This means our pathfinding is currently slow. Not so slow that it causes any noticeable performance issues, but slow enough that we don't currently allow all NPCs to be using it at all times and put severe restrictions on its current capabilities. This is why - for example - cave raptors don't jump across gaps to chase after the player. We can't pre-populate the world with 'jump points' because the world could change at any time and each block of additional distance an NPC can jump over a gap is a large additional cost for every search.
这意味着我们目前的寻路速度较慢。虽然不至于造成明显的性能问题,但速度慢到我们目前不允许所有 NPC 一直使用它,并且对其现有功能进行了严格限制。例如,这就是为什么洞穴迅猛龙不会跳过缝隙追逐玩家的原因。我们无法预先在世界中设置“跳跃点”,因为世界随时可能发生变化,而 NPC 能够跳过缝隙的距离每增加一个方块,都会给每次搜索带来巨大的额外开销。
We don't expect this to change in time for the early access release, but we're committed to improving our pathfinding as a whole and have already begun work on developing a new method that could solve most of these issues should it prove viable.
我们预计在抢先体验版发布之前这种情况不会改变,但我们致力于整体改进寻路算法,并且已经开始着手开发一种新方法,如果证明可行,该方法可以解决其中的大部分问题。
So what's next? 接下来呢?
Tooling is high up on our priority list. If we want to support modders properly, we need to give them the tools they need to make creating NPCs fun! This won't include a full suite of debugging tools at first, but we'll pull together what we can.工具开发是我们工作的重中之重。如果我们想更好地支持模组制作者,就必须为他们提供所需的工具,让他们能够更轻松地创建 NPC!一开始我们可能无法提供全套调试工具,但我们会尽力整合。
We also need to address the issues with pathfinding and movement while dealing with technical debt to ensure that we're not creating performance bottlenecks when players face off against multiple NPCs in complex environments. There's a lot we can improve on here to make sure that combat feels enjoyable, even at this early stage.
我们还需要解决寻路和移动方面的问题,同时处理技术债务,以确保玩家在复杂环境中与多个 NPC 对战时不会出现性能瓶颈。即使在早期阶段,我们也有很多可以改进的地方,以确保战斗体验能够令人满意。
Adding more templates will also help to liven up the world a bit more, with bespoke behaviours introducing life to the cultures of Orbis' many different species. These are also intended to serve as further inspiration and examples for modders seeking to create their own more complex NPCs - or can be used directly if the behaviour fits!
添加更多模板也有助于让世界更加生动,定制的行为将为奥比斯众多不同物种的文化注入活力。这些模板也旨在为希望创建更复杂 NPC 的模组制作者提供更多灵感和范例——如果行为合适,也可以直接使用!
All of this leads towards the potential for creating proper bosses - encounters that will push all our PvE systems to their absolute limits. There's a lot of work required to reach this point - far more than has been listed here - but we're laying it out step by step and working our way through it. With a bit more time, we'll make it all work!
这一切都指向一个可能:打造真正的首领——那些能将我们所有 PvE 系统推向极限的战斗。要达到这个目标,需要做很多工作——远不止这里列出的这些——但我们正在一步一步地规划,努力完成。再过一段时间,我们就能把一切都做好!
A headstart: debug commands 入门指南:调试命令
This post was originally written to be posted before our early access release. In the time since, we've put quite a bit of effort into trying to make NPCs more accessible to modders. While we don't have a visual editor or deep debugging just yet, we've added a number of different visualisations to make it easier to understand how your NPCs will function (and tracked down a number of bugs on our end through using them too!). Some of these features are still in development, but here is a sneak peak into our work in progress and what’s coming soon in future releases.这篇文章最初是为抢先体验版发布而写的。自那以后,我们投入了大量精力,力求让 NPC 对模组制作者更加友好。虽然我们目前还没有可视化编辑器或深度调试功能,但我们添加了一些不同的可视化效果,以便您更容易理解 NPC 的运作方式(我们也通过这些可视化效果追踪到了一些我们自己发现的 bug!)。 其中一些功能仍在开发中,但这里先让您先睹为快,看看我们正在进行的工作以及未来版本中即将推出的内容。
Each of these visualisations can be enabled by toggling certain NPC debug flags on individual NPCs. This is done by using the NPC debug command while keeping the NPC in your view. You can do this by typing /npc debug set <flag> in the chat console in-game or by adding the flags as a comma-separated list in the Debug property of the NPC role itself. Running the command /npc debug presets provides a full list of available flags and preset sets of flags that can be used, but the most useful visualization flags are detailed below.
可以通过切换特定 NPC 的调试标志来启用这些可视化效果。具体操作方法是:在 NPC 处于视野范围内时,使用 NPC 调试命令。您可以在游戏内的聊天控制台中输入 `/npc debug set <flag>` ,或者将标志以逗号分隔的形式添加到 NPC 角色的 “调试” 属性中。运行命令 ` /npc debug presets` 可以查看所有可用标志和预设标志集的完整列表,但最常用的可视化标志详述如下。
/npc debug set VisAiming
You can use it to determine what the NPCs actually shoot at. Works for NPCs that have aim instructions in their logic.
你可以用它来确定 NPC 实际射击的目标。适用于逻辑中包含瞄准指令的 NPC。
/npc debug set VisMarkedTargets
Visualises all current marked targets locked onto by the NPC. In most of our standard templates, the NPC has a single LockedTarget which is usually the entity they're actively engaged in combat with. Useful for understanding how and when the NPC changes focus, as well as exactly what their current focus is in a crowd.
可视化显示 NPC 当前锁定的所有目标。在我们的大多数标准模板中,每个 NPC 只有一个锁定目标 ,通常是他们正在交战的目标。这有助于了解 NPC 如何以及何时切换目标,以及在人群中准确了解他们的当前目标。
/npc debug set VisSensorRanges
Visualises all currently checked Mob sensor ranges as rings and view sectors, as well as which entities in range are being matched by which of these sensors. With how these sensors are generally used in our NPCs, this gives a quick visual overview of the 'sensory capabilities' of an NPC. Note that though these are displayed as sectors and rings, they are technically spheres and cones that can be bounded by height conditions.
以环形和扇形区域的形式可视化所有当前已检查的生物传感器范围,并显示范围内哪些实体与哪些传感器匹配。鉴于这些传感器通常在 NPC 中的使用方式,这可以快速直观地概览 NPC 的“感知能力”。请注意,虽然这些区域显示为扇形和环形区域,但实际上它们是球体和圆锥体,其边界可能受高度条件限制。
The first screenshot shows the Bear sleeping and only having one sensor active. On the second screenshot the Bear has hearing, vision, and absolute detection range. Even though the Sheep are detected by the vision radius (they have target marks) they are outside of the view cone. The sheep family is still safe!
第一张截图显示熊正在睡觉,只有一个传感器处于激活状态。第二张截图显示熊的听觉、视觉和绝对探测范围都已开启。虽然绵羊在视野范围内(它们有目标标记),但它们位于视野锥之外。绵羊一家仍然安全!
/npc debug set VisLeashPosition
Visualises the NPC's current leash position.
可视化 NPC 当前的牵引绳位置。
/npc debug set VisFlock
Visualises the flock (NPC group) associated with this NPC. This display includes marking the leader of the flock and all NPCs that are currently members of the flock.
可视化与此 NPC 关联的 NPC 群体(NPC 组)。此显示包括标记群体首领以及所有当前属于该群体的 NPC。
2026年2月11日发布
原文链接: https://hytale.com/news/2026/2/npc-technical-rundown
原文链接: https://hytale.com/news/2026/2/npc-technical-rundown