Exe*_*sis 3 xna artificial-intelligence behavior-tree
你如何为游戏制作强大的AI /脚本系统?
1)对于所有NPC的/环境/实体,你给他们一个单独的行为树(等patrolBehavior,allyBehavior,vendorBehavior,doorBehavior)?如果屏幕上有500个单元,我应该在树上进行完整传递(从root - > node/action)还是应该对所有单元进行单节点进度?
2)我在update()函数中做了AI逻辑......但我听说有些游戏有自己独立的AI线程,有什么想法吗?
3)我想知道如何将我的游戏分成几个部分/章节......我是否使用一个简单的变量(EVENT ="Mission 3")来表示玩家的表现如何,并使其全部呈线性?然后利用上面树上的变量?
我会尽力回答你的问题.
我在静态类中执行所有分支逻辑和行为树,例如:
 public static class Behavior
{
    //Branch
    public static Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) {
        return () => { if (cond()) { ifTrue(); } else { ifFalse(); } };
        }
    public static Action Sequencer(Action a, Action b) {
          return () => { a(); b(); }
        }
    //Example trees
    public static Func<bool> ifPlayerIsInSight = () => { return true; /*...true iff WorldState shows guard can see player...*/};
    public static Action shootAtPlayer = () => { /*...aim guard's weapon at player and fire...*/ };
    public static Func<bool> ifUnderFire = () => { return true; /*...true iff WorldState shows guard hears player gunfire...*/};
    public static Action takeCover = () => { /*...guard runs for nearest shelter... */};
    public static Action walkBackAndForthGuardingDoorway = () => { /*...default guard patrol behaviour...*/ };
    public static Action patrollingGuardBehaviour =
      Selector(Behavior.ifPlayerIsInSight, Behavior.shootAtPlayer,
        Selector(Behavior.ifUnderFire, Behavior.takeCover,
          Behavior.walkBackAndForthGuardingDoorway));
}
在LateUpdate()或last中执行此操作,因此它不会滞后主循环.
它是由你决定.您可以在每个行为树中实现"状态",或者将其拆分并管理在哪个时间使用.