private void ApplySplashEffect(double depth, Rigidbody body)
        {
            if (depth > 1)
            {
                return;
            }

            float mag = body.velocity.magnitude * 0.02f;

            if (mag > 0.05)
            {
                FXMonger.Splash(part.transform.position, mag);
            }
        }
        private bool CheckDieOnHighVelocity(Rigidbody body)
        {
            Vector3d velVector = body.velocity + Krakensbane.GetFrameVelocityV3f();

            double vertVec = Vector3d.Dot(velVector, vessel.upAxis);

            if (Math.Abs(vertVec) > part.crashTolerance * vertCrashTolFactor)
            {
                GameEvents.onCrashSplashdown.Fire(new EventReport(FlightEvents.SPLASHDOWN_CRASH, part, part.partInfo.title, "", 0, ""));
                FXMonger.Splash(part.transform.position, 10);
                part.Die();
                return(true);
            }
            double horizVel = (velVector - vertVec * vessel.upAxis).magnitude;

            if (horizVel > part.crashTolerance * horizCrashTolFactor)
            {
                GameEvents.onCrashSplashdown.Fire(new EventReport(FlightEvents.SPLASHDOWN_CRASH, part, part.partInfo.title, "", 0, ""));
                FXMonger.Splash(part.transform.position, 10);
                part.Die();
                return(true);
            }
            return(false);
        }
Beispiel #3
0
            void Update()
            {
                if (FlightGlobals.ActiveVessel == null)
                {
                    return;
                }

                if (FlightGlobals.currentMainBody != _body)
                {
                    return;
                }

                // Is the vessel within the sphere of influence?
                if (FlightGlobals.ship_altitude < influenceAltitude)
                {
                    if (MapView.MapIsEnabled)
                    {
                        MapView.ExitMapView();
                    }

                    if (FlightGlobals.ActiveVessel.GetComponent <CameraShake>() == null)
                    {
                        FlightGlobals.ActiveVessel.gameObject.AddComponent <CameraShake>().ShakeAmount = 2;
                        if (!String.IsNullOrEmpty(entryMessage))
                        {
                            ScreenMessages.PostScreenMessage(entryMessage, entryMsgDuration);
                        }
                    }
                }
                else
                {
                    CameraShake shake = FlightGlobals.ActiveVessel.GetComponent <CameraShake>();
                    if (shake != null)
                    {
                        Destroy(shake);
                        if (!String.IsNullOrEmpty(exitMessage))
                        {
                            ScreenMessages.PostScreenMessage(exitMessage, exitMsgDuration);
                        }
                    }

                    return;
                }

                // Are we within the jump range?
                if (FlightGlobals.ship_altitude < jumpMaxAltitude && FlightGlobals.ship_altitude > jumpMinAltitude)
                {
                    // Disable the log output
                    PDebug.DebugLevel l = PDebug.debugLevel;
                    PDebug.debugLevel = PDebug.DebugLevel.None;

                    for (Int32 i = 0; i < 5; i++)
                    {
                        Vector3    random = UnityEngine.Random.onUnitSphere;
                        GameObject effect = FXMonger.Splash(
                            FlightGlobals.ship_position + random * 50, 1000).effectObj;
                        effect.transform.localScale = Vector3.one * 10;
                        effect.transform.up         = -random;
                    }

                    // Update the FXMonger
                    FXMonger[] mongers = FindObjectsOfType <FXMonger>();
                    for (Int32 i = 0; i < mongers.Length; i++)
                    {
                        mongers[i].SendMessage("LateUpdate");
                    }

                    PDebug.debugLevel = l;

                    // If the Pe is within the jump range, jump
                    if (FlightGlobals.ship_altitude - _lastAlt > 0)
                    {
                        // Move the vessel to the new orbit
                        if (FlightGlobals.ActiveVessel.GetComponent <JumpMarker>() == null)
                        {
                            MakeOrbit(FlightGlobals.ActiveVessel.orbitDriver, _partner);
                            FlightGlobals.ActiveVessel.gameObject.AddComponent <JumpMarker>();
                        }
                    }
                }
                else
                {
                    // Heat up the vessel
                    for (Int32 i = 0; i < FlightGlobals.ActiveVessel.Parts.Count; i++)
                    {
                        FlightGlobals.ActiveVessel[i].temperature += heatRate;
                    }

                    // Remove the jump marker if neccessary
                    JumpMarker jump = FlightGlobals.ActiveVessel.GetComponent <JumpMarker>();
                    if (jump != null)
                    {
                        Destroy(jump);
                    }
                }

                _lastAlt = FlightGlobals.ship_altitude;
            }
Beispiel #4
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (vessel.mainBody.ocean && part.GetComponent <Rigidbody>() != null)
            {
                if (part.partBuoyancy != null)
                {
                    Destroy(part.partBuoyancy);
                }

                double partAltitude = Vector3d.Distance(forcePoint.position, vessel.mainBody.position) - vessel.mainBody.Radius - buoyancyVerticalOffset;
                if (partAltitude < 0d)
                {
                    // float code

                    double floatMultiplier = Math.Max(0d, -Math.Max(partAltitude, -buoyancyRange)) / buoyancyRange;

                    if (floatMultiplier > 0f)
                    {
                        Vector3d up     = (this.vessel.GetComponent <Rigidbody>().position - this.vessel.mainBody.position).normalized;
                        Vector3d uplift = up * buoyancyForce * floatMultiplier;

                        //float relativeDirection = Vector3.Dot(vessel.GetComponent<Rigidbody>().velocity.normalized, up);

                        if (vessel.verticalSpeed < maxVerticalSpeed) // || relativeDirection < 0f) // if you are going down, apply force regardless, of going up, limit up speed
                        {
                            this.part.GetComponent <Rigidbody>().AddForceAtPosition(uplift, forcePoint.position);
                        }
                    }

                    // set water drag

                    part.GetComponent <Rigidbody>().drag = dragInWater;

                    // splashed status

                    splashed             = true;
                    part.WaterContact    = true;
                    part.vessel.Splashed = true;

                    // part destruction

                    if (base.GetComponent <Rigidbody>().velocity.magnitude > waterImpactTolerance)
                    {
                        GameEvents.onCrashSplashdown.Fire(new EventReport(FlightEvents.SPLASHDOWN_CRASH, this.part, this.part.partInfo.title, "ocean", 0, "FSbuoyancy: Hit the water too hard"));
                        this.part.Die();
                        return;
                    }

                    //FX

                    if (splashFXEnabled)
                    {
                        splashTimer -= Time.deltaTime;
                        if (splashTimer <= 0f)
                        {
                            splashTimer = splashCooldown;
                            if (base.GetComponent <Rigidbody>().velocity.magnitude > 6f && partAltitude > -buoyancyRange) // don't splash if you are deep in the water or going slow
                            {
                                if (Vector3.Distance(base.transform.position, FlightGlobals.camera_position) < 500f)
                                {
                                    FXMonger.Splash(base.transform.position, base.GetComponent <Rigidbody>().velocity.magnitude / 50f);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (splashed)
                    {
                        splashed = false;

                        // set air drag
                        part.GetComponent <Rigidbody>().drag = 0f;

                        part.WaterContact = false;
                        part.vessel.checkSplashed();
                    }
                }
            }
        }