Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        seekTarget();

        if (master.aggroed && EnemyStats.getAggro() != null)
        {
            attack();
        }
    }
Ejemplo n.º 2
0
    public override void sUpdate()
    {
        Rigidbody2D aggroRigid;

        if (aggroRigid = enemyStats.getAggro())
        {
            //Debug.Log((aggroRigid.position.x - transform.position.x) + " " + xdir);
            if (Mathf.Sign(aggroRigid.position.x - transform.position.x) != xdir)
            {
                xFlip();
            }
        }
        enemyRigid.velocity = new Vector2(0, gameObject.GetComponent <Rigidbody2D> ().velocity.y);
    }
    public Vector2 CalcTrajectory()
    {
        //float g = projectile.GetComponent<Rigidbody2D> ().gravityScale;
        Vector2 Direction = new Vector2(float.NaN, float.NaN);

        Vector2 SpawnPosition = transform.position;
        Vector2 TargetPos     = enemyStats.getAggro().position;

        if (!usesGravity)
        {
            Direction = TargetPos - SpawnPosition;
            Direction.Normalize();
            return(Direction * thrust);
        }

        float yf = TargetPos.y - SpawnPosition.y;
        float xf = TargetPos.x - SpawnPosition.x;
        float g  = -Physics2D.gravity.y * gravScale;

        /*
         * float theta = Mathf.Pow(thrust, 4) + 2 * g * yf * thrust * thrust - g * g * xf * xf;
         * theta = -xf * Mathf.Sqrt( -Mathf.Sqrt(theta) + g * yf + thrust * thrust);
         * theta = Mathf.Acos(theta / (thrust * Mathf.Sqrt(2*yf * yf + 2*xf * xf)));
         *
         * float vx = Mathf.Cos(theta);
         * float vyo = Mathf.Sin(theta);
         */
        //float vx = thrust / Mathf.Sqrt (Mathf.Pow ((yf - Physics2D.gravity.y * xf * xf / 2) / xf, 2) + 1);
        //float vyo = Mathf.Sqrt (thrust * thrust - vx * vx);
        float b     = thrust * thrust - yf * g;
        float discr = b * b - g * g * (xf * xf + yf * yf);

        //

        float discRoot = Mathf.Sqrt(discr);
        float tMax     = Mathf.Sqrt((b + discRoot) * 2 / (g * g));
        float tMin     = Mathf.Sqrt((b - discRoot) * 2 / (g * g));
        float t        = tMin + (tMax - tMin) * arc;
        float vx       = xf / t;
        float vyo      = yf / t + t * g / 2;

        Direction = new Vector2(vx, vyo);
        //Debug.Log (Direction.magnitude);
        //Direction.Normalize ();

        //return Direction;
        return(Direction);
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (cycleTime > 0)
        {
            timeCounter += Time.deltaTime;
            if (timeCounter >= cycleTime)
            {
                timeCounter -= cycleTime;
                changePattern();
                //changeMovement ();
            }
        }
        if (EnemyStats.helpless <= 0)
        {
            if (!aggroed || aMove == null)
            {
                moveTimer += Time.deltaTime;
                if (moveTimer >= Mathf.Abs(moveDur [currMove]))
                {
                    moveTimer -= Mathf.Abs(moveDur [currMove]);
                    changeMovement();
                }
            }
            jumpTimer = Mathf.Max(0, jumpTimer - Time.deltaTime);


            if (EnemyStats.getAggro() != null)
            {
                if (!aggroDelay || currMove >= moveLoopStart)
                {
                    if (!aggroed)
                    {
                        aggroed = true;
                        if (aMove != null)
                        {
                            getCycleMove().switchFrom();
                            getCycleMove().enabled = false;
                            if (aMove.xdir != getCycleMove().xdir)
                            {
                                aMove.xdir = getCycleMove().xdir;
                            }
                            aMove.switchTo();
                            aMove.enabled = true;
                        }
                    }
                }
            }
            else
            {
                if (aggroed)
                {
                    aggroed = false;
                    if (aMove != null)
                    {
                        aMove.switchFrom();
                        aMove.enabled = false;
                        if (aMove.xdir != getCycleMove().xdir)
                        {
                            getCycleMove().xdir = aMove.xdir;
                        }
                        getCycleMove().switchTo();
                        getCycleMove().enabled = true;
                    }
                }
            }
        }
        else
        {
            getCurrMove().switchFrom();
            getCurrMove().enabled = false;
            EnemyStats.helpless  -= Time.deltaTime;
            if (EnemyStats.helpless <= 0)
            {
                getCurrMove().switchTo();
                getCurrMove().enabled = true;
            }
        }
    }