参考链接:
https://www.cnblogs.com/01zxs/p/9863715.html
https://blog.csdn.net/AcmHonor/article/details/123234763
https://blog.csdn.net/u012632851/article/details/89647097?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-89647097-blog-82943972.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-89647097-blog-82943972.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=3
https://blog.csdn.net/wuming2016/article/details/116858357
BehaviorDesigner下载
https://gitcode.net/linxinfa/unitybehaviordesigner
一.制作一颗简单的行为树
如下,是一颗简单的怪物行为树,当看见主角时,向主角移动;否则保持站立状态
AICanSeeObj.cs
1 using BehaviorDesigner.Runtime; 2 using BehaviorDesigner.Runtime.Tasks; 3 using UnityEngine; 4 5 public class AICanSeeObj : Conditional 6 { 7 public float distance = 2f; 8 public SharedTransform target; 9 10 public override TaskStatus OnUpdate() 11 { 12 if (Vector3.Distance(transform.position, target.Value.position) < distance) 13 { 14 return TaskStatus.Success; 15 } 16 else 17 { 18 return TaskStatus.Failure; 19 } 20 } 21 }
AIMoveTo.cs
1 using BehaviorDesigner.Runtime; 2 using BehaviorDesigner.Runtime.Tasks; 3 using UnityEngine; 4 5 //移动到指定的目标 6 public class AIMoveTo : Action 7 { 8 public float speed = 1f; 9 public SharedTransform target; 10 11 public override TaskStatus OnUpdate() 12 { 13 if (Vector3.Distance(transform.position, target.Value.position) < 0.1f) 14 { 15 return TaskStatus.Success; 16 } 17 transform.position = Vector3.MoveTowards(transform.position, target.Value.position, speed * Time.deltaTime); 18 return TaskStatus.Running; 19 } 20 }
AIIdle.cs
1 using BehaviorDesigner.Runtime.Tasks; 2 3 public class AIIdle : Action 4 { 5 public override TaskStatus OnUpdate() 6 { 7 return TaskStatus.Running; 8 } 9 }
二.行为树的特点以及中断机制
在行为树中,一般一个节点返回Success或者Failure后,这个节点就不会再执行了(除非行为树重新执行或者该节点在Repeater节点下)
如下,白色是主角,红色是怪物,一开始两者距离较远,怪物处于Idle状态,即使后面拉近距离,AIIdle也不会被打断,不符合我们设定的AI逻辑(距离较近时向主角移动)
标签:UnityAI,中断,TaskStatus,blog,position,using,机制,BehaviorDesigner,public From: https://www.cnblogs.com/lyh916/p/17034983.html