Пример #1
0
    private void OnDrawGizmos()
    {
        if (Time.time > ExplosionTriggerTime)
        {
            float ExplosionTime = Time.time - ExplosionTriggerTime;
            float Radius        = ExplosionRadius.Evaluate(ExplosionTime);
            float Force         = ExplosionForce.Evaluate(ExplosionTime);

            Gizmos.color = new Color(0.5f + Force / 500, 0.5f - Force / 500, 0, Mathf.Clamp(Mathf.Abs(Force) / 1000, 0.1f, 0.75f));
            Gizmos.DrawSphere(transform.position, Radius);
        }
    }
Пример #2
0
    void OnTriggerEnter(Collider co)
    {
        if (co.CompareTag("Explosion Radius"))
        {
            ExplosionRadius sdc = co.GetComponent <ExplosionRadius>();

            float fExpDistance = Vector3.Distance(co.ClosestPoint(transform.position), co.transform.position);
            if (fExpDistance < sdc.GetRadius())
            {
                Debug.Log("Rocket affects on enemy: " + (sdc.GetDamage() * Mathf.Cos(fExpDistance * Mathf.PI / (2.0f * sdc.GetRadius()))));
                nCurrDurability -= (int)(sdc.GetDamage() * Mathf.Cos(fExpDistance * Mathf.PI / (2.0f * sdc.GetRadius())));
            }
        }
    }
Пример #3
0
    private void FixedUpdate()
    {
        if (Time.time > ExplosionTriggerTime)
        {
            if (Time.time > ExplosionEndTime)
            {
                Destroy(this);
            }

            float ExplosionTime = Time.time - ExplosionTriggerTime;
            float Radius        = ExplosionRadius.Evaluate(ExplosionTime);
            float Force         = ExplosionForce.Evaluate(ExplosionTime);

            if (Radius <= 0)
            {
                return;
            }

            Collider[] HitColliders = Physics.OverlapSphere(transform.position, Radius);

            foreach (Collider HitCollider in HitColliders)
            {
                if (HitCollider.gameObject == this.gameObject)
                {
                    continue;
                }
                Rigidbody Body = HitCollider.GetComponent <Rigidbody>();
                if (Body == null)
                {
                    continue;
                }
                float BodyDistance = Vector3.Distance(Body.transform.position, transform.position);

                Body.AddExplosionForce(Force * ForceFalloff.Evaluate(BodyDistance / Radius), ExplosionLocation, 0.0f, 0.0f, ForceMode.Force);
            }
        }
    }