Exemple #1
0
    void BombChase()
    {
        if (!focussedBomb || !chase)
        {
            return;
        }

        if (Vector2.Distance(focussedBomb.position, transform.position) > m_Character.hitRadius) // Move
        {
            if (Mathf.Abs(focussedBomb.position.y - transform.position.y) < 2f &&
                Mathf.Abs(focussedBomb.position.x - transform.position.x) > m_Character.hitRadius)
            {
                float h = focussedBomb.position.x > transform.position.x ? 0.5f : -0.5f;
                m_Character.Move(h, m_Jump);
            }
            else
            {
                m_Character.Move(0, m_Jump);
            }
        }
        else
        {
            if (attackCooldown < 0)
            {
                m_Character.Attack(true);
                m_Character.Move(0, m_Jump);
                attackCooldown = 1f;

                if (pirate == Pirate.cucumber)
                {
                    focussedBomb.GetComponent <Bomb>().BlowOut();
                }
                if (pirate == Pirate.whale)
                {
                    focussedBomb.GetComponent <Bomb>().Eat();
                }
                else if (pirate != Pirate.captain)
                {
                    chase = false;
                }
                focussedBomb = null;
            }
        }
    }
        private void FixedUpdate()
        {
            if (target == null)
            {
                return;
            }

            var tPos  = target.transform.position;
            var xDiff = tPos.x - transform.position.x;
            var yDiff = tPos.y - transform.position.y;
            var hStep = hGravity * Time.fixedDeltaTime;

            if (xDiff > targetRange)
            {
                hInput += hStep;
                m_Jump  = yDiff >= targetYRange;
            }
            else if (xDiff < -targetRange)
            {
                hInput -= hStep;
                m_Jump  = yDiff >= targetYRange;
            }
            else
            {
                if (hInput > hDeadZone)
                {
                    hInput -= hStep;
                }
                else if (hInput < -hDeadZone)
                {
                    hInput += hStep;
                }
                else
                {
                    hInput = 0.0f;
                }
            }

            if (minAttackDist.x >= Mathf.Abs(xDiff) && minAttackDist.y >= Mathf.Abs(yDiff))
            {
                m_Character.Attack();
            }

            hInput = Mathf.Clamp(hInput, -1.0f, 1.0f);

            m_Character.Move(hInput, false, m_Jump);
            m_Jump = false;
        }