void ReceiveImpact(ref ImpactForce impact) //Applies the impact { if (impact.direction.magnitude > 0.2) { Move(impact.direction, impact.force); } // consumes the impact energy each cycle: impact.direction = Vector3.Lerp(impact.direction, Vector3.zero, impact.decay * Time.deltaTime); }
ImpactForce GenerateRandomImpact() //Calculates impact force, direction and decay { ImpactForce f = new ImpactForce(); f.force = Random.Range(20.0f, 60.0f); f.decay = Random.Range(0.25f, 2f); switch (side) { case PartSide.Left: f.side = PartSide.Left; f.direction = new Vector3(-1, Random.Range(-1.0f, 1.0f), 0); f.direction = f.direction.normalized; break; case PartSide.Right: f.side = PartSide.Right; f.direction = new Vector3(1, Random.Range(-1.0f, 1.0f), 0); f.direction = f.direction.normalized; break; } return(f); }
// Use this for initialization void Start() { impact = new ImpactForce(); gravity = 9.8f; }
void Explode() //Initiates explosion { explode = true; transform.parent = null; impact = GenerateRandomImpact(); }
protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("Flags", true, out subEle); subEle.Value = Flags.ToString(); ele.TryPathTo("Type", true, out subEle); subEle.Value = Type.ToString(); ele.TryPathTo("Gravity", true, out subEle); subEle.Value = Gravity.ToString("G15"); ele.TryPathTo("Speed", true, out subEle); subEle.Value = Speed.ToString("G15"); ele.TryPathTo("Range", true, out subEle); subEle.Value = Range.ToString("G15"); ele.TryPathTo("Light", true, out subEle); Light.WriteXML(subEle, master); ele.TryPathTo("MuzzleFlash/Light", true, out subEle); MuzzleFlashLight.WriteXML(subEle, master); ele.TryPathTo("TracerChance", true, out subEle); subEle.Value = TracerChance.ToString("G15"); ele.TryPathTo("Explosion/AltTrigger/Proximity", true, out subEle); subEle.Value = ExplosionAltTriggerProximity.ToString("G15"); ele.TryPathTo("Explosion/AltTrigger/Timer", true, out subEle); subEle.Value = ExplosionAltTriggerTimer.ToString("G15"); ele.TryPathTo("Explosion/Form", true, out subEle); Explosion.WriteXML(subEle, master); ele.TryPathTo("Sound", true, out subEle); Sound.WriteXML(subEle, master); ele.TryPathTo("MuzzleFlash/Duration", true, out subEle); subEle.Value = MuzzleFlashDuration.ToString("G15"); ele.TryPathTo("FadeDuration", true, out subEle); subEle.Value = FadeDuration.ToString("G15"); ele.TryPathTo("ImpactForce", true, out subEle); subEle.Value = ImpactForce.ToString("G15"); ele.TryPathTo("Sound/Countdown", true, out subEle); SoundCountdown.WriteXML(subEle, master); ele.TryPathTo("Sound/Disable", true, out subEle); Sounddisable.WriteXML(subEle, master); ele.TryPathTo("DefaultWeaponSource", true, out subEle); DefaultWeaponSource.WriteXML(subEle, master); ele.TryPathTo("XRotation", true, out subEle); subEle.Value = XRotation.ToString("G15"); ele.TryPathTo("YRotation", true, out subEle); subEle.Value = YRotation.ToString("G15"); ele.TryPathTo("ZRotation", true, out subEle); subEle.Value = ZRotation.ToString("G15"); ele.TryPathTo("BouncyMult", true, out subEle); subEle.Value = BouncyMult.ToString("G15"); }