/// <summary>
    /// Перемещение
    /// </summary>
    protected override void Move(OrientationEnum _orientation)
    {
        bool  crouching    = (groundState == GroundStateEnum.crouching);
        float currentSpeed = speed * ((underWater || crouching) ? waterCoof : 1f);

        rigid.velocity = new Vector3((wallCheck.WallInFront()) ? 0f : Input.GetAxis("Horizontal") * currentSpeed, rigid.velocity.y);
        if (orientation != _orientation)
        {
            Turn(_orientation);
        }
    }
Exemplo n.º 2
0
    protected bool calmDown = false;//Успокаивается ли персонаж

    #endregion //parametres

    protected virtual void FixedUpdate()
    {
        if (!immobile)
        {
            if (agressive && mainTarget != null && employment > 2)
            {
                Vector3 targetPosition = mainTarget.transform.position;
                if (Vector2.Distance(targetPosition, transform.position) > attackDistance)
                {
                    if (!wallCheck.WallInFront() && (precipiceCheck.WallInFront()))
                        Move((OrientationEnum)Mathf.RoundToInt(Mathf.Sign(targetPosition.x - transform.position.x)));
                    else if ((targetPosition - transform.position).x * (int)orientation < 0f)
                        Turn();
                }
                else
                {
                    if ((targetPosition - transform.position).x * (int)orientation < 0f)
                        Turn();
                    Attack();
                }
            }
            else if (!agressive)
            {
                if ((Vector2.Distance(waypoint, transform.position) < attackDistance) || (wallCheck.WallInFront() || !(precipiceCheck.WallInFront())))
                {
                    Turn();
                    Patrol();
                }
                else
                {
                    Move((OrientationEnum)Mathf.RoundToInt(Mathf.Sign(waypoint.x - transform.position.x)));
                }
            }
        }
        else if (moveOut)
        {
            MoveOut();
        }
        Animate(new AnimationEventArgs("groundMove"));
        Analyse();
    }
    /// <summary>
    /// Анализ окружающей персонажа обстановки
    /// </summary>
    protected override void Analyse()
    {
        if (groundCheck.WallInFront())
        {
            groundState = GroundStateEnum.grounded;
        }
        else
        {
            groundState = GroundStateEnum.inAir;
        }

        if ((groundState == GroundStateEnum.grounded))
        {
            bool crouching = false;
            if (Physics2D.OverlapCircle(wallAboveCheck.position, groundRadius, whatIsGround) || Input.GetButton("Flip"))
            {
                groundState = GroundStateEnum.crouching;
                crouching   = true;
            }
            if (employment > 6)
            {
                Crouch(crouching);
            }

            if (fallSpeed > minDamageFallSpeed)
            {
                TakeDamage(Mathf.Round((fallSpeed - minDamageFallSpeed) * damagePerFallSpeed), true);
            }
            if (fallSpeed > minDamageFallSpeed / 10f)
            {
                Animate(new AnimationEventArgs("fall"));
            }
            fallSpeed = 0f;
        }
        else
        {
            Crouch(false);
            fallSpeed = -rigid.velocity.y;
        }

        bool _underWater = Physics2D.OverlapCircle(waterCheck.position, groundRadius, LayerMask.GetMask("Water"));

        if (underWater != _underWater)
        {
            underWater = _underWater;
            WaterIndicator waterIndicator = waterCheck.GetComponent <WaterIndicator>();
            if (_underWater)
            {
                rigid.gravityScale = .6f;
                waterIndicator.StartCoroutine(SuffocateProcess());
            }
            else
            {
                rigid.gravityScale = 1f;
                waterIndicator.StopAllCoroutines();
                AirSupply = maxAirSupply;
            }
            Animate(new AnimationEventArgs("waterSplash"));
        }

        if (onLadder)
        {
            if (!Physics2D.OverlapCircle(transform.position - transform.up * ladderCheckOffset, ladderStep, LayerMask.GetMask("ladder")))
            {
                LadderOff();
            }
        }
    }
    protected float divingPrecision = .01f; //Точность определения местоположения противника, когда босс находится под ним

    #endregion                              //parametres

    protected virtual void FixedUpdate()
    {
        if (agressive)
        {
            Vector3 targetPosition = currentTarget.transform.position;
            if (!diving)
            {
                if (employment > 2)
                {
                    float distance = Vector3.SqrMagnitude(targetPosition - transform.position);
                    if (distance > attackDistance * attackDistance)
                    {
                        if (!wallCheck.WallInFront())
                        {
                            Move((OrientationEnum)Mathf.RoundToInt(Mathf.Sign(targetPosition.x - transform.position.x)));
                        }
                        else if ((targetPosition - transform.position).x * (int)orientation < 0f)
                        {
                            Turn();
                        }
                    }
                    else if (employment > 8)
                    {
                        if ((targetPosition - transform.position).x * (int)orientation < 0f)
                        {
                            Turn();
                        }
                        Attack();
                    }
                }
            }

            else
            {
                //Здесь описаны все фазы совершения особой атаки босса

                Vector3 direction = (divingPosition - transform.position).normalized;

                switch (divingPhase)
                {
                case 1:
                {
                    //Сначала босс опускается под землю
                    rigid.velocity = direction * speed * 2;
                    if (Mathf.Abs(transform.position.y - divingPosition.y) < divingPrecision)
                    {
                        Vector3 pos = transform.position;
                        transform.position = new Vector3(pos.x, divingPosition.y, pos.z);
                        divingPhase++;
                        divingPosition = new Vector3(targetPosition.x, pos.y, pos.z);
                        rigid.velocity = Vector2.zero;
                    }
                    break;
                }

                case 2:
                {
                    //"Заныривает" под противника
                    if (!wallCheck.WallInFront())
                    {
                        Move((OrientationEnum)Mathf.RoundToInt(Mathf.Sign(targetPosition.x - transform.position.x)));
                    }
                    else if ((targetPosition - transform.position).x * (int)orientation < 0f)
                    {
                        Turn();
                    }
                    if (Mathf.Abs(targetPosition.x - transform.position.x) < divingPrecision)
                    {
                        Vector3 pos = transform.position;
                        transform.position = new Vector3(targetPosition.x, pos.y, pos.z);
                        divingPhase++;
                        divingPosition = transform.position + diveDownOffset * Vector3.up;

                        Animate(new AnimationEventArgs("attack", "SpecialAttack", 0));
                        employment = Mathf.Clamp(employment - 8, 0, maxEmployment);
                        hitBox.SetHitBox(new HitClass(damage, -1f, attackSize, attackPosition, hitForce));
                        rigid.velocity = Vector2.zero;
                    }

                    break;
                }

                case 3:
                {
                    //И выходит из-под земли с атакой
                    rigid.velocity = direction * diveOutSpeed;
                    if (Mathf.Abs(transform.position.y - divingPosition.y) < divingPrecision)
                    {
                        Vector3 pos = transform.position;
                        transform.position = new Vector3(pos.x, divingPosition.y, pos.z);
                        employment         = Mathf.Clamp(employment + 8, 0, maxEmployment);
                        SetDiving(false);
                        rigid.velocity = Vector2.zero;
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
            }

            if (employment > 2)
            {
                if ((targetPosition - transform.position).x * (int)orientation < 0f)
                {
                    Turn();
                }
            }
        }

        Analyse();
        Animate(new AnimationEventArgs("groundMove"));
    }