示例#1
0
    protected void FireAtPlayer()
    {
        if (InvaderManager.I.PlayerObject.GetCurrentHealth > 0 && lastFire < Time.time)
        {
            ParticleSystem.EmitParams eparam = new ParticleSystem.EmitParams();

            float accuracy = AccuracyBasedOnDifficulty.Evaluate(InvaderManager.GetDifficulty());

            Vector2 tVel = InvaderManager.I.PlayerObject.GetVelocity / Time.deltaTime;

            float tMagn = tVel.magnitude;
            float delta = tMagn / ProjectileSpeed;

            Vector2 desPoint = InvaderManager.I.PlayerObject.transform.position;
            desPoint += (tVel * delta);
            desPoint += Random.insideUnitCircle * (1f - accuracy) * AccuracyDistance;

            Vector2 dir = desPoint - new Vector2(transform.position.x, transform.position.y);
            Debug.DrawRay(desPoint, dir, Color.green, 1f);

            eparam.velocity = dir.normalized * ProjectileSpeed;
            eparam.position = transform.position;

            ParticleSystem.Emit(eparam, 1);
            lastFire = Time.time + MinFireInterval + Random.Range(0f, 2f);
        }
    }
示例#2
0
    protected bool Aggro()
    {
        float dist = 0f;

        if (!GoHostile(out dist))
        {
            return(false);
        }
        else
        {
            Vector2 tVel = InvaderManager.I.PlayerObject.GetVelocity / Time.deltaTime;

            float   mySpeed  = SpeedBasedOnDifficulty.Evaluate(InvaderManager.GetDifficulty());
            float   tMagn    = tVel.magnitude;
            float   delta    = tMagn / mySpeed;
            Vector2 desPoint = InvaderManager.I.PlayerObject.transform.position;
            desPoint += (tVel * delta);

            transform.position = Vector2.MoveTowards(transform.position, desPoint, mySpeed * Time.deltaTime);

            FireAtPlayer();

            return(true);
        }
    }
示例#3
0
    protected bool GoHostile(out float dist)
    {
        float difficulty = InvaderManager.GetDifficulty();

        dist = Vector2.Distance(InvaderManager.I.PlayerObject.transform.position, transform.position);
        float aggroDist = AggroBasedOnDifficulty.Evaluate(difficulty);

        if (InvaderManager.I.PlayerObject.GetCurrentHealth <= 0)
        {
            return(false);
        }

        return(dist < aggroDist);
    }
示例#4
0
    protected void Roam()
    {
        if (Time.time > nextRoamUpdate)
        {
            float xBias = InvaderManager.I.PlayerObject.transform.position.x - transform.position.x;

            xBias = Mathf.Clamp(xBias, -1f, 1f) * 0.4f;

            Vector2 dir = (Vector2.right * xBias) + Random.insideUnitCircle;
            dir.y         *= 0.3f; // More horizontal movement
            roamDir        = dir.normalized;
            roamSpeed      = SpeedBasedOnDifficulty.Evaluate(InvaderManager.GetDifficulty()) * Random.Range(0.5f, 1f);
            nextRoamUpdate = Time.time + Random.Range(0.5f, 4f);
        }

        if (FireDistance > Vector3.Distance(InvaderManager.I.PlayerObject.transform.position, transform.position))
        {
            FireAtPlayer();
        }

        curRoamDir         = Vector3.RotateTowards(curRoamDir, roamDir, 2f * Time.deltaTime, 4f * Time.deltaTime);
        transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x, transform.position.y) + curRoamDir, roamSpeed * Time.deltaTime);
    }