Пример #1
0
    public void seekTarget()
    {
        Collider2D[] hits;
        hits = Physics2D.OverlapCircleAll(EnemyRigid.position, range);          //get all colliders within range

        PlayerMovement playerMove = null;

        for (int i = 0; i < hits.Length; i++)                                                           //iterate through colliders and see if any classify as player

        {
            if ((playerMove = hits [i].GetComponentInParent <PlayerMovement> ()))
            {
                Rigidbody2D playerRigid = playerMove.GetComponentInParent <Rigidbody2D> ();
                float       theta       = Vector2.SignedAngle(transform.right, playerRigid.position - EnemyRigid.position);

                if (master.getCurrMove().xdir < 0)
                {
                    theta = 180 - theta;
                    if (theta > 180)
                    {
                        theta = theta - 360;
                    }
                }                //Debug.Log (theta);


                if (visionStart > visionEnd)
                {
                    if (theta < visionStart && theta > visionEnd)
                    {
                        EnemyStats.setAggro(null);
                        continue;
                    }
                }
                else
                {
                    if (theta < visionStart || theta > visionEnd)                                       //check if player is within acceptable angle range for field of vision
                    {
                        EnemyStats.setAggro(null);
                        continue;
                    }
                }
                if (EnemyStats.getAggro() == null)
                {
                    EnemyStats.setAggro(playerRigid);
                }
                //Debug.Log ("I see you");
                break;
            }
        }
        if (playerMove == null)
        {
            EnemyStats.setAggro(null);
            //Debug.Log ("I see nobody");
        }
    }