——个人笔记
本人学习《Unity人工智能游戏开发》和AI有关视觉系统所作笔记
感知系统
Sense类
感知系统通常在游戏中比较多使用的就是听觉、视觉和触觉(通常直接用碰撞体来实现)。这个笔记主要总结了视觉的,听觉的可以用一个触发器来实现。Player有个bool值来说明player是否发出声音,enemy用触发器检测有玩家进入而且发出声音则向位置走去。
我们会写一个Sense类基类(Sense.cs),让各感知系统继承此基类。
public class Sense:MonoBehaviour{
public bool bDebug=true;//用来调试的,后期可以删除
public Aspect.aspect aspectName =Aspect.aspect.Enemy;//标签,枚举类型(当前只有Player,Enemy)
public float detectionRate=1.0f; //可以设置此值来实现感知暂时失效效果和初始后开始开启感知系统的时间(可以自行更改,也可以不要)
protected float elapsedTime=0.0f;//计时器,配合detectionRate,如果detectionRate不要则此也不要。
protected virtual void Initialize(){}
protected virtual void UpdateSense(){}
void Start(){
elapsedTime=0.0f;
Initialize();
}
void Update(){
UpdateSense();
}
}