Example #1
0
        private void FixedUpdate()
        {
            if (Target)
            {
                if (CheckRayCollideWithEntity(transform.position, Target.position - transform.position, "Wall"))
                {
                    if (CheckRayCollideWithEntity(transform.position,
                                                  Target.GetComponent <Renderer>().bounds.max - transform.position, "Wall"))
                    {
                        lastPosTarget = Target.GetComponent <Renderer>().bounds.min;
                    }
                    else if (CheckRayCollideWithEntity(transform.position,
                                                       Target.GetComponent <Renderer>().bounds.min - transform.position, "Wall"))
                    {
                        lastPosTarget = Target.GetComponent <Renderer>().bounds.max;
                    }

                    minRotate = CheckRotate(transform.localEulerAngles.y - angleView / 2);
                    maxRotate = CheckRotate(transform.localEulerAngles.y + angleView / 2);

                    listWayPoint.Add(lastPosTarget);

                    Target    = null;
                    pathState = PATHSTATES.LostTarget;
                }
            }
        }
Example #2
0
        public void NewTarget(Transform player)
        {
            pathState = PATHSTATES.Hunting;
            Target    = player;

            levelMgr.EnemyDetectPlayer(enemy.gameObject);
        }
Example #3
0
        private void Hunting()
        {
            Move(Target.position);

            listWayPoint.Add(transform.position);

            if (Vector3.Distance(transform.position, Target.position) > rangeOfView)
            {
                levelMgr.EnemyLostPlayer(enemy.gameObject);
                Target    = null;
                pathState = PATHSTATES.Repositioning;
            }
        }
Example #4
0
        private void LostTarget()
        {
            Move(lastPosTarget);

            if (Vector3.Distance(transform.position, lastPosTarget) < 1)
            {
                pathState = PATHSTATES.Research;
            }

            if (CheckRayCollideWithEntity(transform.position, transform.forward, "Wall", 1f))
            {
                levelMgr.EnemyLostPlayer(enemy.gameObject);
                listWayPoint.Remove(listWayPoint[listWayPoint.Count - 1]);
                pathState = PATHSTATES.Repositioning;
            }
        }
Example #5
0
        private void Repositioning()
        {
            if (!CheckRayCollideWithEntity(transform.position, posStart - transform.position, "Wall"))
            {
                listWayPoint.RemoveRange(1, listWayPoint.Count - 1);
            }

            Vector3 currentWaypoint = listWayPoint[listWayPoint.Count - 1];

            if (Vector3.Distance(transform.position, currentWaypoint) < 1)
            {
                listWayPoint.Remove(currentWaypoint);

                if (listWayPoint.Count == 0)
                {
                    pathState = PATHSTATES.Waiting;
                }
            }

            Move(currentWaypoint);
        }
Example #6
0
        private void Research()
        {
            transform.RotateAround(transform.position, Vector3.up, 4 * sign * rotationSpeed * Time.deltaTime);

            if (sign == 0 && Target == null)
            {
                sign      = -1;
                pathState = PATHSTATES.Repositioning;

                levelMgr.EnemyLostPlayer(enemy.gameObject);
            }

            if (sign < 0 && transform.localEulerAngles.y <= minRotate)
            {
                sign *= -1;
            }
            else if (sign > 0 && transform.localEulerAngles.y >= maxRotate)
            {
                sign = 0;
            }
        }