Пример #1
0
        void Detonate(Vector3 pos)
        {
            BDArmorySettings.numberOfParticleEmitters--;

            ExplosionFX.CreateExplosion(pos, blastRadius, blastForce, sourceVessel, rb.velocity.normalized, explModelPath, explSoundPath);
            GameObject.Destroy(gameObject);             //destroy rocket on collision
        }
Пример #2
0
        public static void CreateExplosion(Vector3 position, float radius, float power, Vessel sourceVessel, Vector3 direction, string explModelPath, string soundPath)
        {
            GameObject go;
            AudioClip  soundClip;

            go        = GameDatabase.Instance.GetModel(explModelPath);
            soundClip = GameDatabase.Instance.GetAudioClip(soundPath);


            Quaternion rotation     = Quaternion.LookRotation(VectorUtils.GetUpDirection(position));
            GameObject newExplosion = (GameObject)GameObject.Instantiate(go, position, rotation);

            newExplosion.SetActive(true);
            ExplosionFX eFx = newExplosion.AddComponent <ExplosionFX>();

            eFx.exSound                 = soundClip;
            eFx.audioSource             = newExplosion.AddComponent <AudioSource>();
            eFx.audioSource.minDistance = 25;
            eFx.audioSource.maxDistance = 2500;

            if (power <= 5)
            {
                eFx.audioSource.minDistance = 4f;
                eFx.audioSource.maxDistance = 1000;
                eFx.audioSource.priority    = 9999;
            }
            foreach (KSPParticleEmitter pe in newExplosion.GetComponentsInChildren <KSPParticleEmitter>())
            {
                pe.emit = true;
            }

            DoExplosionDamage(position, power, radius, sourceVessel);
        }
Пример #3
0
        private void Detonate()
        {
            if (part != null)
            {
                part.temperature = part.maxTemp + 100;
            }
            Vector3 position = part.vessel.CoM;

            ExplosionFX.CreateExplosion(position, blastRadius, blastPower, blastHeat, vessel, FlightGlobals.getUpAxis(),
                                        "BDArmory/Models/explosion/explosionLarge", "BDArmory/Sounds/explode1");
        }
Пример #4
0
 public void Detonate()
 {
     if (!hasDetonated)
     {
         hasDetonated = true;
         if (part != null)
         {
             part.temperature = part.maxTemp + 100;
         }
         Vector3 position = transform.position + part.rb.velocity * Time.fixedDeltaTime;
         ExplosionFX.CreateExplosion(position, blastRadius, blastPower, blastHeat, vessel, FlightGlobals.getUpAxis(), "BDArmory/Models/explosion/explosionLarge", "BDArmory/Sounds/explode1");
     }
 }
Пример #5
0
        void Detonate(Vector3 pos)
        {
            BDArmorySettings.numberOfParticleEmitters--;

            ExplosionFX.CreateExplosion(pos, blastRadius, blastForce, blastHeat, sourceVessel, rb.velocity.normalized, explModelPath, explSoundPath);

            foreach (var emitter in pEmitters)
            {
                if (emitter.useWorldSpace)
                {
                    emitter.gameObject.AddComponent <BDAParticleSelfDestruct>();
                    emitter.transform.parent = null;
                }
            }

            GameObject.Destroy(gameObject);             //destroy rocket on collision
        }
Пример #6
0
        public void CreateExplosion(Part part)
        {
            float explodeScale = 0;

            foreach (var current in part.Resources)
            {
                switch (current.resourceName)
                {
                case "LiquidFuel":
                    explodeScale += (float)current.amount;
                    break;

                case "Oxidizer":
                    explodeScale += (float)current.amount;
                    break;
                }
            }
            explodeScale /= 100;
            part.explode();
            ExplosionFX.CreateExplosion(part.partTransform.position, explodeScale * blastRadius, explodeScale * blastPower * 2,
                                        explodeScale * blastHeat, part.vessel, FlightGlobals.upAxis, explModelPath, explSoundPath);
        }
Пример #7
0
 void Detonate(Vector3 pos)
 {
     ExplosionFX.CreateExplosion(pos, blastRadius, blastForce, sourceVessel, FlightGlobals.getUpAxis(), subExplModelPath, subExplSoundPath);
     GameObject.Destroy(gameObject);             //destroy bullet on collision
 }
Пример #8
0
        void FixedUpdate()
        {
            float distanceFromStart = Vector3.Distance(transform.position, startPosition);

            if (!gameObject.activeInHierarchy)
            {
                return;
            }
            flightTimeElapsed += TimeWarp.fixedDeltaTime;       //calculate flight time for drag purposes

            if (bulletDrop && FlightGlobals.RefFrameIsRotating)
            {
                currentVelocity += FlightGlobals.getGeeForceAtPosition(transform.position) * TimeWarp.fixedDeltaTime;
            }
            if (dragType == BulletDragTypes.NumericalIntegration)
            {
                Vector3 dragAcc = currentVelocity * currentVelocity.magnitude * (float)FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(transform.position), FlightGlobals.getExternalTemperature(transform.position));
                dragAcc *= 0.5f;
                dragAcc /= ballisticCoefficient;

                currentVelocity -= dragAcc * TimeWarp.fixedDeltaTime;       //numerical integration; using Euler is silly, but let's go with it anyway
            }


            if (tracerLength == 0)
            {
                bulletTrail.SetPosition(0, transform.position + (currentVelocity * tracerDeltaFactor * TimeWarp.fixedDeltaTime / TimeWarp.CurrentRate) - (FlightGlobals.ActiveVessel.rb_velocity * TimeWarp.fixedDeltaTime));
            }
            else
            {
                bulletTrail.SetPosition(0, transform.position + ((currentVelocity - sourceOriginalV).normalized * tracerLength));
            }
            if (fadeColor)
            {
                FadeColor();
                bulletTrail.material.SetColor("_TintColor", currentColor * tracerLuminance);
            }



            bulletTrail.SetPosition(1, transform.position);



            currPosition = gameObject.transform.position;

            if (distanceFromStart > maxDistance)
            {
                //GameObject.Destroy(gameObject);
                KillBullet();
                return;
            }

            if (collisionEnabled)
            {
                float dist = initialSpeed * TimeWarp.fixedDeltaTime;

                Ray        ray = new Ray(prevPosition, currPosition - prevPosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, dist, 557057))
                {
                    bool  penetrated = true;
                    Part  hitPart    = null;                   //determine when bullet collides with a target
                    float hitAngle   = Vector3.Angle(currentVelocity, -hit.normal);

                    if (bulletType != PooledBulletTypes.Explosive)                    //dont do bullet damage if it is explosive
                    {
                        float impactVelocity = currentVelocity.magnitude;
                        if (dragType == BulletDragTypes.AnalyticEstimate)
                        {
                            float analyticDragVelAdjustment = (float)FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(currPosition), FlightGlobals.getExternalTemperature(currPosition));
                            analyticDragVelAdjustment *= flightTimeElapsed * initialSpeed;
                            analyticDragVelAdjustment += 2 * ballisticCoefficient;

                            analyticDragVelAdjustment = 2 * ballisticCoefficient * initialSpeed / analyticDragVelAdjustment; //velocity as a function of time under the assumption of a projectile only acted upon by drag with a constant drag area

                            analyticDragVelAdjustment = analyticDragVelAdjustment - initialSpeed;                            //since the above was velocity as a function of time, but we need a difference in drag, subtract the initial velocity
                            //the above number should be negative...
                            impactVelocity += analyticDragVelAdjustment;                                                     //so add it to the impact velocity

                            if (impactVelocity < 0)
                            {
                                impactVelocity = 0;                                     //clamp the velocity to > 0, since it could drop below 0 if the bullet is fired upwards
                            }
                            //Debug.Log("flight time: " + flightTimeElapsed + " BC: " + ballisticCoefficient + "\ninit speed: " + initialSpeed + " vel diff: " + analyticDragVelAdjustment);
                        }

                        //hitting a vessel Part

                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        /////////////////////////////////////////////////[panzer1b] HEAT BASED DAMAGE CODE START//////////////////////////////////////////////////////////////
                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                        try
                        {
                            hitPart = Part.FromGO(hit.rigidbody.gameObject);
                        }
                        catch (NullReferenceException)
                        {
                        }


                        if (hitPart != null)                        //see if it will ricochet of the part
                        {
                            penetrated = !RicochetOnPart(hitPart, hitAngle, impactVelocity);
                        }
                        else                         //see if it will ricochet off scenery
                        {
                            float reflectRandom = UnityEngine.Random.Range(-150f, 90f);
                            if (reflectRandom > 90 - hitAngle)
                            {
                                penetrated = false;
                            }
                        }


                        if (hitPart != null && !hitPart.partInfo.name.Contains("Strut"))                                                                             //when a part is hit, execute damage code (ignores struts to keep those from being abused as armor)(no, because they caused weird bugs :) -BahamutoD)
                        {
                            float heatDamage = (mass / (hitPart.crashTolerance * hitPart.mass)) * impactVelocity * impactVelocity * BDArmorySettings.DMG_MULTIPLIER; //how much heat damage will be applied based on bullet mass, velocity, and part's impact tolerance and mass
                            if (!penetrated)
                            {
                                heatDamage = heatDamage / 8;
                            }
                            if (BDArmorySettings.INSTAKILL)                             //instakill support, will be removed once mod becomes officially MP
                            {
                                heatDamage = (float)hitPart.maxTemp + 100;              //make heat damage equal to the part's max temperture, effectively instakilling any part it hits
                            }
                            if (BDArmorySettings.DRAW_DEBUG_LABELS)
                            {
                                Debug.Log("Hit! damage applied: " + heatDamage);                                                                //debugging stuff
                            }
                            if (hitPart.vessel != sourceVessel)
                            {
                                hitPart.temperature += heatDamage;                                                             //apply heat damage to the hit part.
                            }
                            float overKillHeatDamage = (float)(hitPart.temperature - hitPart.maxTemp);

                            if (overKillHeatDamage > 0)                                 //if the part is destroyed by overheating, we want to add the remaining heat to attached parts.  This prevents using tiny parts as armor
                            {
                                overKillHeatDamage *= hitPart.crashTolerance;           //reset to raw damage
                                float numConnectedParts = hitPart.children.Count;
                                if (hitPart.parent != null)
                                {
                                    numConnectedParts++;
                                    overKillHeatDamage         /= numConnectedParts;
                                    hitPart.parent.temperature += overKillHeatDamage / (hitPart.parent.crashTolerance * hitPart.parent.mass);

                                    for (int i = 0; i < hitPart.children.Count; i++)
                                    {
                                        hitPart.children[i].temperature += overKillHeatDamage / hitPart.children[i].crashTolerance;
                                    }
                                }
                                else
                                {
                                    overKillHeatDamage /= numConnectedParts;
                                    for (int i = 0; i < hitPart.children.Count; i++)
                                    {
                                        hitPart.children[i].temperature += overKillHeatDamage / hitPart.children[i].crashTolerance;
                                    }
                                }
                            }
                        }

                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        /////////////////////////////////////////////////[panzer1b] HEAT BASED DAMAGE CODE END////////////////////////////////////////////////////////////////
                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                        //hitting a Building
                        DestructibleBuilding hitBuilding = null;
                        try
                        {
                            hitBuilding = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>();
                        }
                        catch (NullReferenceException)
                        {
                        }
                        if (hitBuilding != null && hitBuilding.IsIntact)
                        {
                            float damageToBuilding = mass * initialSpeed * initialSpeed * BDArmorySettings.DMG_MULTIPLIER / 12000;
                            if (!penetrated)
                            {
                                damageToBuilding = damageToBuilding / 8;
                            }
                            hitBuilding.AddDamage(damageToBuilding);
                            if (hitBuilding.Damage > hitBuilding.impactMomentumThreshold)
                            {
                                hitBuilding.Demolish();
                            }
                            if (BDArmorySettings.DRAW_DEBUG_LINES)
                            {
                                Debug.Log("bullet hit destructible building! Damage: " + (damageToBuilding).ToString("0.00") + ", total Damage: " + hitBuilding.Damage);
                            }
                        }
                    }

                    if (hitPart == null || (hitPart != null && hitPart.vessel != sourceVessel))
                    {
                        if (!penetrated && !hasBounced)
                        {
                            //ricochet
                            hasBounced = true;
                            if (BDArmorySettings.BULLET_HITS)
                            {
                                BulletHitFX.CreateBulletHit(hit.point, hit.normal, true);
                            }

                            tracerStartWidth /= 2;
                            tracerEndWidth   /= 2;

                            transform.position = hit.point;
                            currentVelocity    = Vector3.Reflect(currentVelocity, hit.normal);
                            currentVelocity    = (hitAngle / 150) * currentVelocity * 0.65f;

                            Vector3 randomDirection = UnityEngine.Random.rotation * Vector3.one;

                            currentVelocity = Vector3.RotateTowards(currentVelocity, randomDirection, UnityEngine.Random.Range(0f, 5f) * Mathf.Deg2Rad, 0);
                        }
                        else
                        {
                            if (bulletType == PooledBulletTypes.Explosive)
                            {
                                ExplosionFX.CreateExplosion(hit.point - (ray.direction * 0.1f), radius, blastPower, blastHeat, sourceVessel, currentVelocity.normalized, explModelPath, explSoundPath);
                            }
                            else if (BDArmorySettings.BULLET_HITS)
                            {
                                BulletHitFX.CreateBulletHit(hit.point, hit.normal, false);
                            }



                            //GameObject.Destroy(gameObject); //destroy bullet on collision
                            KillBullet();
                            return;
                        }
                    }
                }

                /*
                 * if(isUnderwater)
                 * {
                 *      if(FlightGlobals.getAltitudeAtPos(transform.position) > 0)
                 *      {
                 *              isUnderwater = false;
                 *      }
                 *      else
                 *      {
                 *              rigidbody.AddForce(-rigidbody.velocity * 0.15f);
                 *      }
                 * }
                 * else
                 * {
                 *      if(FlightGlobals.getAltitudeAtPos(transform.position) < 0)
                 *      {
                 *              isUnderwater = true;
                 *              //FXMonger.Splash(transform.position, 1);
                 *              //make a custom splash here
                 *      }
                 * }
                 */
            }

            if (bulletType == PooledBulletTypes.Explosive && airDetonation && distanceFromStart > detonationRange)
            {
                //detonate
                ExplosionFX.CreateExplosion(transform.position, radius, blastPower, blastHeat, sourceVessel, currentVelocity.normalized, explModelPath, explSoundPath);
                //GameObject.Destroy(gameObject); //destroy bullet on collision
                KillBullet();
                return;
            }


            prevPosition = currPosition;

            //move bullet
            transform.position += currentVelocity * Time.fixedDeltaTime;
        }
Пример #9
0
        void FixedUpdate()
        {
            float distanceFromStart = Vector3.Distance(transform.position, startPosition);

            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            if (bulletDrop && FlightGlobals.RefFrameIsRotating)
            {
                currentVelocity += FlightGlobals.getGeeForceAtPosition(transform.position) * TimeWarp.fixedDeltaTime;
            }


            if (tracerLength == 0)
            {
                bulletTrail.SetPosition(0, transform.position + (currentVelocity * 1.35f * TimeWarp.fixedDeltaTime / TimeWarp.CurrentRate) - (FlightGlobals.ActiveVessel.rb_velocity * TimeWarp.fixedDeltaTime));
            }
            else
            {
                bulletTrail.SetPosition(0, transform.position + ((currentVelocity - sourceOriginalV).normalized * tracerLength));
            }
            if (fadeColor)
            {
                FadeColor();
                bulletTrail.material.SetColor("_TintColor", currentColor);
            }



            bulletTrail.SetPosition(1, transform.position);



            currPosition = gameObject.transform.position;

            if (distanceFromStart > maxDistance)
            {
                //GameObject.Destroy(gameObject);
                KillBullet();
                return;
            }

            if (collisionEnabled)
            {
                float dist = initialSpeed * TimeWarp.fixedDeltaTime;

                Ray        ray = new Ray(prevPosition, currPosition - prevPosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, dist, 557057))
                {
                    bool penetrated = true;


                    //hitting a vessel Part

                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    /////////////////////////////////////////////////[panzer1b] HEAT BASED DAMAGE CODE START//////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    Part hitPart = null;                        //determine when bullet collides with a target
                    try{
                        hitPart = Part.FromGO(hit.rigidbody.gameObject);
                    }catch (NullReferenceException) {}

                    float hitAngle = Vector3.Angle(currentVelocity, -hit.normal);
                    if (hitPart != null)                  //see if it will ricochet of the part
                    {
                        penetrated = !RicochetOnPart(hitPart, hitAngle);
                    }
                    else                     //see if it will ricochet off scenery
                    {
                        float reflectRandom = UnityEngine.Random.Range(-150f, 90f);
                        if (reflectRandom > 90 - hitAngle)
                        {
                            penetrated = false;
                        }
                    }


                    if (hitPart != null && !hitPart.partInfo.name.Contains("Strut"))                                                           //when a part is hit, execute damage code (ignores struts to keep those from being abused as armor)(no, because they caused weird bugs :) -BahamutoD)
                    {
                        float heatDamage = (mass / hitPart.crashTolerance) * currentVelocity.magnitude * 50 * BDArmorySettings.DMG_MULTIPLIER; //how much heat damage will be applied based on bullet mass, velocity, and part's impact tolerance
                        if (!penetrated)
                        {
                            heatDamage = heatDamage / 8;
                        }
                        if (BDArmorySettings.INSTAKILL)                         //instakill support, will be removed once mod becomes officially MP
                        {
                            heatDamage = (float)hitPart.maxTemp + 100;          //make heat damage equal to the part's max temperture, effectively instakilling any part it hits
                        }
                        if (BDArmorySettings.DRAW_DEBUG_LINES)
                        {
                            Debug.Log("Hit! damage applied: " + heatDamage); //debugging stuff
                        }
                        if (hitPart.mass <= 0.01)                            //if part mass is below 0.01, instakill it and do minor collateral (anti-exploit and to keep people from abusing near massless or massless crap as armor)
                        {
                            if (hitPart.vessel != sourceVessel)
                            {
                                hitPart.temperature += hitPart.maxTemp + 500;                                                              //make heat damage equal to the part's max temperture, and add 500 extra heat damage which should do minor collateral to teh surrounding parts
                            }
                        }
                        else                            //apply damage normally if no special case present
                        {
                            if (hitPart.vessel != sourceVessel)
                            {
                                hitPart.temperature += heatDamage;                                                              //apply heat damage to the hit part.
                            }
                        }
                    }

                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    /////////////////////////////////////////////////[panzer1b] HEAT BASED DAMAGE CODE END////////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                    //hitting a Building
                    DestructibleBuilding hitBuilding = null;
                    try{
                        hitBuilding = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>();
                    }
                    catch (NullReferenceException) {}
                    if (hitBuilding != null && hitBuilding.IsIntact)
                    {
                        float damageToBuilding = mass * initialSpeed * BDArmorySettings.DMG_MULTIPLIER / 120;
                        if (!penetrated)
                        {
                            damageToBuilding = damageToBuilding / 8;
                        }
                        hitBuilding.AddDamage(damageToBuilding);
                        if (hitBuilding.Damage > hitBuilding.impactMomentumThreshold)
                        {
                            hitBuilding.Demolish();
                        }
                        if (BDArmorySettings.DRAW_DEBUG_LINES)
                        {
                            Debug.Log("bullet hit destructible building! Damage: " + (damageToBuilding).ToString("0.00") + ", total Damage: " + hitBuilding.Damage);
                        }
                    }

                    if (hitPart == null || (hitPart != null && hitPart.vessel != sourceVessel))
                    {
                        if (!penetrated && !hasBounced)
                        {
                            //ricochet
                            hasBounced = true;
                            if (BDArmorySettings.BULLET_HITS)
                            {
                                BulletHitFX.CreateBulletHit(hit.point, hit.normal, true);
                            }

                            transform.position = hit.point;
                            currentVelocity    = Vector3.Reflect(currentVelocity, hit.normal);
                            currentVelocity    = (hitAngle / 150) * currentVelocity * 0.65f;

                            Vector3 randomDirection = UnityEngine.Random.rotation * Vector3.one;

                            currentVelocity = Vector3.RotateTowards(currentVelocity, randomDirection, UnityEngine.Random.Range(0f, 5f) * Mathf.Deg2Rad, 0);
                        }
                        else
                        {
                            if (BDArmorySettings.BULLET_HITS)
                            {
                                BulletHitFX.CreateBulletHit(hit.point, hit.normal, false);
                            }

                            if (bulletType == PooledBulletTypes.Explosive)
                            {
                                ExplosionFX.CreateExplosion(hit.point, radius, blastPower, sourceVessel, currentVelocity.normalized, explModelPath, explSoundPath);
                            }

                            //GameObject.Destroy(gameObject); //destroy bullet on collision
                            KillBullet();
                            return;
                        }
                    }
                }

                /*
                 * if(isUnderwater)
                 * {
                 *      if(FlightGlobals.getAltitudeAtPos(transform.position) > 0)
                 *      {
                 *              isUnderwater = false;
                 *      }
                 *      else
                 *      {
                 *              rigidbody.AddForce(-rigidbody.velocity * 0.15f);
                 *      }
                 * }
                 * else
                 * {
                 *      if(FlightGlobals.getAltitudeAtPos(transform.position) < 0)
                 *      {
                 *              isUnderwater = true;
                 *              //FXMonger.Splash(transform.position, 1);
                 *              //make a custom splash here
                 *      }
                 * }
                 */
            }

            if (bulletType == PooledBulletTypes.Explosive && airDetonation && distanceFromStart > detonationRange)
            {
                //detonate
                ExplosionFX.CreateExplosion(transform.position, radius, blastPower, sourceVessel, currentVelocity.normalized, explModelPath, explSoundPath);
                //GameObject.Destroy(gameObject); //destroy bullet on collision
                KillBullet();
                return;
            }


            prevPosition = currPosition;

            //move bullet
            transform.position += currentVelocity * Time.fixedDeltaTime;
        }