Пример #1
0
    private void HandleExplosion()
    {
        Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, blastRadius);

        foreach (Collider2D col in hitColliders)
        {
            Vector3 pos     = col.transform.position;
            Vector2 impulse = pos - transform.position;

            impulse /= impulse.magnitude;
            impulse *= blastForce;

            float percent = (blastRadius - Vector3.Distance(pos, transform.position)) / blastRadius;

            if (col.tag == "Ship")
            {
                ShipScript ship = col.GetComponent <ShipScript>();
                ship.TakeHit(impulse * percent, pos);
                ship.ApplyDamage(m_damage * percent, m_shieldPenetration);
            }
            else if (col.tag == "Asteroid" || col.tag == "Satellite" || col.tag == "sAsteroid")
            {
                //Rigidbody2D roidRb = col.GetComponent<Rigidbody2D>();
                //roidRb.AddForce( impulse * percent, ForceMode2D.Impulse );
                Satellite sat = col.GetComponent <Satellite>();
                sat.ApplyDamage(m_damage * percent, Vector2.zero, pos, false);
            }
        }
    }
Пример #2
0
    private void HandleAsteroidSplitExplosion()
    {
        float blastRadius = mass * 2f;
        float blastForce  = 40f * mass;

        Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, blastRadius);

        foreach (Collider2D col in hitColliders)
        {
            Vector3 pos     = col.transform.position;
            Vector2 impulse = pos - transform.position;

            impulse /= impulse.magnitude;
            impulse *= blastForce;

            float percent = (blastRadius - Vector3.Distance(pos, transform.position)) / blastRadius;

            if (col.tag == "Ship")
            {
                ShipScript ship = col.GetComponent <ShipScript>();
                ship.TakeHit(impulse / 2 * percent, pos);
                ship.ApplyDamage(1.0f * mass * percent, 0.0f);
            }
            else if (col.tag == "Satellite" || col.tag == "sAsteroid" && col.gameObject != gameObject)
            {
                //Rigidbody2D roidRb = col.GetComponent<Rigidbody2D>();
                //roidRb.AddForce( impulse * percent, ForceMode2D.Impulse );
                Satellite sat = col.GetComponent <Satellite>();
                sat.ApplyDamage(0, impulse * 2 * percent, pos, false);
            }
        }
    }
Пример #3
0
 private void HandleHit(Collider2D col, Vector2 hitPos)
 {
     if (col.tag == "Ship")
     {
         ShipScript ship = col.GetComponent <ShipScript>();
         ship.TakeHit(Vector2.zero, hitPos);
         ship.ApplyDamage(m_damage, m_shieldPenetration);
     }
     else if (col.tag == "Asteroid")
     {
         // Do same sort of thing as with Ship
         Satellite sat = col.GetComponent <Satellite>();
         sat.ApplyDamage(m_damage, Vector2.zero);
     }
     DisableProjectile();
 }
Пример #4
0
    private void HandleHit(RaycastHit2D hit)
    {
        GameObject go  = hit.collider.gameObject;
        Vector2    dir = (hit.point - (Vector2)transform.position).normalized;

        if (go.tag == "Ship")
        {
            ShipScript ship = go.GetComponent <ShipScript>();
            ship.TakeHit(dir, hit.point);

            ship.ApplyDamage(damage * Time.deltaTime);
        }
        else if (go.tag == "Asteroid")
        {
            // Do same sort of thing as with Ship
            Satellite sat = go.GetComponent <Satellite>();
            sat.ApplyDamage(damage, dir);
        }
    }
Пример #5
0
    private void HandleExplosion()
    {
        float blastRadius = 16.0f;
        float blastForce  = 50f * mass;

        Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, blastRadius);

        //Setup explosion to throw particles around based on blast radius
        Explode explode = ms_explosion.GetComponent <Explode>();

        explode.ParticleRadius = blastRadius;
        explode.SpriteRadius   = mass;

        Instantiate(ms_explosion, transform.position, Quaternion.identity);

        foreach (Collider2D col in hitColliders)
        {
            Vector3 pos     = col.transform.position;
            Vector2 impulse = pos - transform.position;

            impulse /= impulse.magnitude;
            impulse *= blastForce;

            float percent = (blastRadius - Vector3.Distance(pos, transform.position)) / blastRadius;

            if (col.tag == "Ship")
            {
                ShipScript ship = col.GetComponent <ShipScript>();
                ship.TakeHit(impulse * percent, pos);
                ship.ApplyDamage(20.0f * mass * percent, 0.0f);
            }
            else if (col.tag == "Asteroid" || col.tag == "sAsteroid")
            {
                //Rigidbody2D roidRb = col.GetComponent<Rigidbody2D>();
                //roidRb.AddForce( impulse * percent, ForceMode2D.Impulse );
                Satellite sat = col.GetComponent <Satellite>();
                //sat.ApplyDamage( 10.0f * percent, impulse, pos, false );
            }
        }
    }