Ejemplo n.º 1
0
        private void pursue()
        {
            Vector3 desired_velocity = target.position - self.transform.position;
            float   distance         = Vector3.Distance(target.position, self.transform.position);
            float   centerDistance   = Vector3.Distance(self.centerPoint.transform.position, self.transform.position);

            if (checkAttackDelegate(distance, self.hp, self.anim, transform))
            {
                desired_velocity = Vector3.zero;
                float addtime = (self.anim.GetCurrentAnimatorStateInfo(0).length < 1) ? self.anim.GetCurrentAnimatorStateInfo(0).length : 1;
                attackPeriod = Time.time + addtime;
                //When outside territory range, back to search mode
            }
            else if (centerDistance >= self.centerPoint.territoryRange && distance > 6)
            {
                self.changeState(gameObject.AddComponent <EnemyFSM.Search>());
            }
            else
            {
                if (Time.time > attackPeriod)
                {
                    self.m_CharCtrl.Move((transform.forward * self.maxAttackVelocity * Time.deltaTime) + new Vector3(0, self.MoveDir.y, 0));
                }
                self.anim.SetBool("Attack", false);
            }

            self.anim.SetFloat("Speed", desired_velocity.magnitude);
        }
Ejemplo n.º 2
0
        private Vector3 escape()
        {
            Vector3 newPos = (self.transform.position - target.position) + self.transform.position;

            float distance = Vector3.Distance(target.position, self.transform.position);

            transform.LookAt(newPos);
            self.m_CharCtrl.Move((transform.forward * self.maxAttackVelocity * Time.deltaTime) + new Vector3(0, self.MoveDir.y, 0));


            if (distance > safeRange)
            {
                self.changeState(gameObject.AddComponent <EnemyFSM.Search>());
            }

            self.anim.SetFloat("Speed", newPos.magnitude);
            return(newPos);
        }