Example #1
0
    public void Observe()
    {
        if (isDead)
        {
            return;
        }

        setMoveType(observe);
        observe.setIsObserve(true);
        observe.move();

        int _action = observe.getAction();

        anim.SetInteger("state", _action);

        isDetected = viewAngle.FoundTarget(target, findRange, angle);

        if (isDetected == true)
        {
            Vector3 _dir = (target.transform.position - transform.position).normalized;
            _dir.y = 0;

            transform.rotation = Quaternion.LookRotation(_dir);

            StartCoroutine(Look());
        }
    }
Example #2
0
    void Update()
    {
        direction   = (target.transform.position - transform.position).normalized;
        direction.y = 0;


        RaycastHit _hit;

        // Debug.DrawRay(transform.position, direction * findRange, Color.blue);

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

        isFind = viewAngle.FoundTarget(target, findRange, angle);


        if (isDead)
        {
            Die();
            return;
        }

        if (AI.enabled == false)
        {
            AI.enabled = true;
        }

        if (observe.getIsObserve())
        {
            if (!isFind)
            {
                Observe();
            }

            else
            {
                if (Physics.Raycast(transform.position, direction, out _hit, findRange))
                {
                    if (_hit.transform.tag.Equals("Player"))
                    {
                        observe.setIsObserve(false);
                        anim.SetInteger("state", 1);
                        //observe 상태일 때 action이 0 이면 움직이지 않는 경우를 대비
                        AI.isStopped = false;
                        findCount    = 1;
                    }
                    else
                    {
                        Observe();
                    }
                }
            }
        }
        else
        {
            if (!returnToHome.getIsReturn() && findCount == 1)
            {
                if (isFind)
                {
                    FollowTarget();

                    if (_distance <= attackRange)
                    {
                        //AI.velocity = Vector3.zero;
                        AI.stoppingDistance = attackRange;
                        anim.SetInteger("state", 2);
                    }
                }
                else
                {
                    returnToHome.setIsReturn(true);
                }
            }

            if (returnToHome.getIsReturn())
            {
                Back();
            }
        }
    }
Example #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            isDead = true;
        }

        direction   = (target.transform.position - transform.position).normalized;
        direction.y = 0;


        RaycastHit _hit;

        // Debug.DrawRay(transform.position, direction * findRange, Color.blue);

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

        isFind = viewAngle.FoundTarget(target, findRange, angle);


        if (isDead)
        {
            Die();
            return;
        }

        if (isObserve)
        {
            if (!isFind)
            {
                ProtectHome();
            }

            else
            {
                if (Physics.Raycast(transform.position, direction, out _hit, findRange))
                {
                    if (_hit.transform.tag.Equals("Player"))
                    {
                        anim.SetInteger("state", 1);
                        findCount    = 1;
                        isObserve    = false;
                        AI.isStopped = false;
                    }
                    else
                    {
                        AI.isStopped = true;
                    }
                }
            }
        }
        else
        {
            if (!returnToHome.getIsReturn() /*&& findCount == 1*/)
            {
                if (findCount == 1)
                {
                    if (isFind)
                    {
                        FollowTarget();
                    }
                    else
                    {
                        if (_distance >= attackRange)
                        {
                            returnToHome.setIsReturn(true);
                        }
                    }


                    if (_distance <= attackRange)
                    {
                        AI.velocity = Vector3.zero;
                        anim.SetInteger("state", 2);
                    }
                }
            }

            if (returnToHome.getIsReturn())
            {
                Back();
            }
        }
    }