public override void Update(List<ICharactor> targets) { //如果目标为空或者死亡,切换回待机模式 if (_chasetarget == null || _chasetarget.BKilled) { CharactorAi.ChangeAiState(new IdleAIState()); return; } //如果目标在可攻击的范围内,切换到攻击模式 if (CharactorAi.TargetRange(_chasetarget, 2)) { CharactorAi.StopMove(); CharactorAi.ChangeAiState(new AttackAIState(theAttackTarget: _chasetarget)); return; } //追赶的目标距离过远,回到待机 if (!CharactorAi.TargetRange(_chasetarget, 15)) { CharactorAi.ChangeAiState(new IdleAIState()); } CharactorAi.Moveto(_chasetarget.transform.position); }
//测试阶段,Ai一直处于锁敌状态 //配合动画事件调整锁敌频率(未实现) public override void Update(List <ICharactor> targets) { CharactorAi.LookTarget(_attackTarget); if (CharactorAi.TargetRange(_attackTarget, 2)) { CharactorAi.Attack(_attackTarget); } else { CharactorAi.ChangeAiState(_chaseAi); } }
public override void Update(List <ICharactor> targets) { Vector3 nowPosition = CharactorAi.GetPosition(); ICharactor theNearTarget = null; float minDist = 999f; foreach (var target in targets) { if (target != null) { if (target.BKilled) { continue; } float dist = Vector3.Distance(nowPosition, target.transform.position); if (dist < minDist) { minDist = dist; theNearTarget = target; } } } Debug.Log(theNearTarget); if (theNearTarget == null) { return; } //如果检测到目标在攻击范围内,则切换到攻击状态 if (CharactorAi.TargetRange(theNearTarget, 2)) { CharactorAi.ChangeAiState(new AttackAIState(theAttackTarget: theNearTarget)); } else //如果不在攻击范围内则切换到追赶状态 { //在有效视野内才可以进行锁定追击 if (CharactorAi.UsefulView(theNearTarget) < 90) { CharactorAi.StopMove(); CharactorAi.ChangeAiState(new ChaseAiState(theTarget: theNearTarget)); } } }
private void Start() { if (!WallpointNetWork) { Debug.Log("无法获取到路径列表"); return; } EventMgr.Instance.AddListener(EventMgr.EVENT_TYPE.EnemyFsmEnter, EnterEvent); //进入状态 SetNextTarget(false); CheckBOnGround(); MyAnimator.SetTrigger("ToEqip"); MyAnimator.SetFloat("Z", 1); CharactorAi.ChangeAiState(new IdleAIState()); CharactorAi.SetAiCharactor(theTarget: this); }