示例#1
0
    public void ApplyForcesAndDamageStep()
    {
        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, currentBlastRadius);

        // find objects in current blast radius

        foreach (Collider hit in colliders)
        {
            GameObject go   = hit.gameObject;
            GameUnit   unit = go.GameUnit();

            if (unit && unit != this)
            {
                // apply force to rigid body if it has one
                Rigidbody rb = hit.GetComponent <Rigidbody>();
                if (rb)
                {
                    rb.AddExplosionForce(pushPower, explosionPos, currentBlastRadius, 0.2f);
                }

                // apply damage to unit
                //float dist = Vector3.Distance(explosionPos, unit.gameObject.transform.position);
                //float maxDamage = 1f;
                //float damage = maxDamage / (1f + dist);

                float a = 3f;
                if (unit.IsOfType(typeof(Vehicle)))
                {
                    unit.ApplyDamage(a * 8f * (1 - DoneRatio()));
                }
                else
                {
                    unit.ApplyDamage(a * 0.2f);
                }
            }
        }
    }
    /// <summary>
    /// When the plasma beam hits something we want to apply damage and destroy the beam.
    /// </summary>

    void OnTriggerEnter(Collider col)
    {
        if (!mIsMine)
        {
            return;
        }

        Rigidbody rb = Tools.FindInParents <Rigidbody>(col.transform);

        if (rb != null)
        {
            Explosive exp = rb.GetComponentInChildren <Explosive>();

            if (exp != null)
            {
                exp.Explode();
            }
            else
            {
                Rigidbody myRb = rigidbody;

                if (myRb != null)
                {
                    Vector3 force = myRb.velocity * myRb.mass * forceOnCollision;
                    Vector3 pos   = transform.position;

                    NetworkRigidbody nrb = NetworkRigidbody.Find(rb);
                    if (nrb != null)
                    {
                        nrb.AddForceAtPosition(force, pos);
                    }
                }
            }
        }

        // Apply damage to the unit, if we hit one
        GameUnit unit = Tools.FindInParents <GameUnit>(col.transform);

        if (unit != null)
        {
            unit.ApplyDamage(damageOnHit);
        }

        // Destroy this beam
        NetworkManager.RemoteDestroy(gameObject);
    }
示例#3
0
    bool OnUpdate(List <ProximityManager.Entry> list)
    {
        if (Time.time > mNextUpdate)
        {
            mNextUpdate = Time.time + 0.5f;

            foreach (ProximityManager.Entry ent in list)
            {
                GameUnit gu = ent.rb.GetComponent <GameUnit>();

                if (gu != null)
                {
                    if (mFaction == null || mFaction.factionID == gu.factionID)
                    {
                        gu.ApplyDamage(-rate * 0.5f);
                    }
                }
            }
        }
        return(true);
    }
示例#4
0
    void OnSpaceshipCollision(Collision col)
    {
        if (!enabled)
        {
            return;
        }
        float impactForce = col.impactForceSum.magnitude;
        float seconds     = Mathf.Max(0f, (impactForce - 15f) * 0.1f);

        mSc.DamageNavigation(seconds);
        GameUnit gu = mSc.GetComponent <GameUnit>();

        if (gu != null)
        {
            gu.ApplyDamage(impactForce * 2f);
        }
        if (Player.ship == mSc)
        {
            ChaseCamera.rumble += impactForce / 50f;
        }
    }