GOAP从理论到实践
Key Concepts
Implement Essentials
一个Goal必须有以下内容:
- Fixed Priority
- IsValid(): 判断是否应该完成这个goal.如果Goal是kill enemy,那么首先得有enemy
- Desired world state
一个Action必须有以下内容:
- IsValid():判断是否能够执行,比如一个action 是 Goto pos X,那么这个函数就返回是否能够到达pos X(是否有路劲)
- PreCondition: 执行动作的前提(可以为空)
World State:
- 本质上是一堆变量的集合
- AI 持有一个当前的State
- 一般来说,一次只会关注world state中的其中几个
How to build a plan
- 按优先级找到第一个valid goal
- 找到一个可以满足goal的action
- 找到一个可以满足上面action 的前提的action
- 一直重复,直到和当前状态匹配
- 如果失败,那么找到第二个goal
将state看成一个节点,effect和precondition看成边,那么build plan就变成了一个寻路问题,可以使用Dijkstra,A*等算法.
shadow of mordor Implementation
背景:
- 每一帧有50个左右的ai在进行计划
优化
减少 world-state variables
-将bool折叠成一个enum
- plan cost和variable count 成正比
- 让plan的长度变短
- 将stand-alone的逻辑移除出planner
Tomb Raider Implementation
Reference
- https://www.youtube.com/watch?v=PaOLBOuyswI&list=PLZWmMt_TbeYdBZKvlsRuuOubPTTfPuZot&index=1&ab_channel=AIandGames
- https://www.youtube.com/watch?v=nEnNtiumgII&list=PLZWmMt_TbeYdBZKvlsRuuOubPTTfPuZot&index=2&ab_channel=TheHappieCat
- https://www.youtube.com/watch?v=gm7K68663rA&list=PLZWmMt_TbeYdBZKvlsRuuOubPTTfPuZot&index=3&ab_channel=GDC2025
- https://www.youtube.com/watch?v=Cb4aL6oTumI&list=PLZWmMt_TbeYdBZKvlsRuuOubPTTfPuZot&index=4&ab_channel=TooLoo
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 VanishingBlog!