Beispiel #1
0
        void FixedUpdate()
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            //gravity
            velocity += FlightGlobals.getGeeForceAtPosition(transform.position) * TimeWarp.fixedDeltaTime
                        + Krakensbane.GetLastCorrection();

            //drag
            velocity -= 0.005f * (velocity + Krakensbane.GetFrameVelocityV3f()) * atmDensity;

            transform.rotation *= Quaternion.Euler(angularVelocity * TimeWarp.fixedDeltaTime);
            transform.position += velocity * TimeWarp.deltaTime;

            if (BDArmorySettings.SHELL_COLLISIONS)
            {
                RaycastHit hit;
                if (Physics.Linecast(transform.position, transform.position + velocity * Time.fixedDeltaTime, out hit,
                                     557057))
                {
                    velocity  = Vector3.Reflect(velocity, hit.normal);
                    velocity *= 0.55f;
                    velocity  = Quaternion.AngleAxis(Random.Range(0f, 90f), Random.onUnitSphere) *
                                velocity;
                }
            }
        }
        public Vector3 GetVelocity(Rigidbody rigidbody, Vector3 refPoint) // from Ferram
        {
            Vector3 newVelocity = Vector3.zero;

            newVelocity += rigidbody.GetPointVelocity(refPoint);
            newVelocity += Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
            return(newVelocity);
        }
Beispiel #3
0
    public Vector3 GetVelocity(Rigidbody rigidbody, Vector3 refPoint) // from Ferram
    {
        Vector3 newVelocity = Vector3.zero;

        //newVelocity = commonRigidBody.velocity + Krakensbane.GetFrameVelocity() + Vector3.Cross(commonRigidBody.angularVelocity, liftTransform.position - commonRigidBody.position);
        newVelocity += rigidbody.GetPointVelocity(refPoint);
        newVelocity += Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
        return(newVelocity);
    }
Beispiel #4
0
        public Vector3d GetVelocity(Vector3 refPoint)
        {
            Vector3d velocity = Vector3.zero;
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (part.Rigidbody)
                    velocity += part.Rigidbody.GetPointVelocity(refPoint);

                velocity += Krakensbane.GetFrameVelocity() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
                velocity -= FARWind.GetWind(FlightGlobals.currentMainBody, part, part.Rigidbody.position);

                return velocity;
            }
            else
                return velocityEditor;
        }
Beispiel #5
0
        public Vector3 GetVelocity(Rigidbody rigidbody, Vector3 refPoint) // from Ferram
        {
            Vector3 newVelocity = Vector3.zero;

            try
            {
                newVelocity += rigidbody.GetPointVelocity(refPoint);
                newVelocity += Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
            }
            catch (Exception e)
            {
                Log.err("FSengineBladed GetVelocity Exception!");
                Log.ex(this, e);
            }
            return(newVelocity);
        }
Beispiel #6
0
        public Vector3 GetVelocity(Rigidbody rigidbody, Vector3 refPoint) // from Ferram
        {
            Vector3 newVelocity = Vector3.zero;

            try
            {
                newVelocity += rigidbody.GetPointVelocity(refPoint);
                newVelocity += Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
            }
            catch (Exception e)
            {
                if (debugMode)
                {
                    Debug.Log("FSengineBladed GetVelocity Exception " + e.GetType().ToString());
                }
            }
            return(newVelocity);
        }
        public Vector3d GetVelocity(Vector3 refPoint)
        {
            Vector3d velocity = Vector3.zero;

            if (HighLogic.LoadedSceneIsFlight)
            {
                if (part.Rigidbody)
                {
                    velocity += part.Rigidbody.GetPointVelocity(refPoint);
                }

                velocity += Krakensbane.GetFrameVelocity() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
                return(velocity);
            }
            else
            {
                return(velocityEditor);
            }
        }
        public Vector3d GetVelocity(Vector3 refPoint)
        {
            Vector3d velocity = Vector3.zero;

            if (start != StartState.Editor)
            {
                if (part.Rigidbody)
                {
                    velocity += part.Rigidbody.GetPointVelocity(refPoint);
                }

                velocity += Krakensbane.GetFrameVelocity() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
                return(velocity);
            }
            else
            {
                return(velocityEditor);
            }
        }
Beispiel #9
0
        private void ApplyGravity()
        {
            KerbalIva.GetComponentCached(ref KerbalRigidbody);
            if (Gravity)
            {
                Vector3 gForce           = FlightGlobals.getGeeForceAtPosition(KerbalIva.transform.position);
                Vector3 centrifugalForce = FlightGlobals.getCentrifugalAcc(KerbalIva.transform.position, FreeIva.CurrentPart.orbit.referenceBody);
                Vector3 coriolisForce    = FlightGlobals.getCoriolisAcc(FreeIva.CurrentPart.vessel.rb_velocity + Krakensbane.GetFrameVelocityV3f(), FreeIva.CurrentPart.orbit.referenceBody);

                gForce           = InternalSpace.WorldToInternal(gForce);
                centrifugalForce = InternalSpace.WorldToInternal(centrifugalForce);
                coriolisForce    = InternalSpace.WorldToInternal(coriolisForce);
                flightForces     = gForce + centrifugalForce + coriolisForce;

                KerbalRigidbody.AddForce(gForce, ForceMode.Acceleration);
                KerbalRigidbody.AddForce(centrifugalForce, ForceMode.Acceleration);
                KerbalRigidbody.AddForce(coriolisForce, ForceMode.Acceleration);
                KerbalRigidbody.AddForce(Krakensbane.GetLastCorrection(), ForceMode.VelocityChange);

                if (FreeIva.SelectedObject != null)
                {
                    Rigidbody rbso = FreeIva.SelectedObject.GetComponent <Rigidbody>();
                    if (rbso == null)
                    {
                        rbso = FreeIva.SelectedObject.AddComponent <Rigidbody>();
                    }
                    rbso.AddForce(gForce, ForceMode.Acceleration);
                    rbso.AddForce(centrifugalForce, ForceMode.Acceleration);
                    rbso.AddForce(coriolisForce, ForceMode.Acceleration);
                }
            }
            else
            {
                KerbalRigidbody.velocity = Vector3.zero;
            }
        }
Beispiel #10
0
 public void FixedUpdate()
 {
     FixAeroFX(afx);
     frameVelocity = Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
 }
Beispiel #11
0
        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.R) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.D))
            {
                debugging = !debugging;
            }

            if (FlightGlobals.ready && (FlightGlobals.ActiveVessel != null))
            {
                Ray ray = new Ray();

                if (afx == null)
                {
                    GameObject fx = GameObject.Find("FXLogic");
                    if (fx != null)
                    {
                        afx = fx.GetComponent <AerodynamicsFX>();
                    }
                }

                foreach (var vessel in FlightGlobals.Vessels)
                {
                    if (vessel.packed)
                    {
                        continue;
                    }

                    float atmDensity = (float)FlightGlobals.getAtmDensity(
                        FlightGlobals.getStaticPressure(vessel.findWorldCenterOfMass()));

                    if (atmDensity < 0.0001f)
                    {
                        continue;
                    }

                    float airspeed = (float)vessel.srf_velocity.magnitude;

                    reentryTemperature = ReentryTemperature(airspeed, atmDensity);

                    if (heatEnabled && (afx != null) && afx.FxScalar > 0)
                    {
                        foreach (Part p in vessel.Parts)
                        {
                            ray.direction = (p.Rigidbody.GetPointVelocity(p.transform.position) + Krakensbane.GetFrameVelocityV3f() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime).normalized;
                            ray.origin    = p.transform.position;

                            var forwardFacing = !Physics.Raycast(ray, 10);
                            p.temperature = Heating(p, forwardFacing);
                        }
                    }
                }

                if (debugging)
                {
                    maxheat = (from p in FlightGlobals.ActiveVessel.Parts
                               select p.temperature).Max();
                    maxheatfail = (from p in FlightGlobals.ActiveVessel.Parts
                                   select p.temperature / p.maxTemp).Max();
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// The flight integrator doesn't seem to update the EVA kerbal's position or velocity for about 0.95s of real-time for some unknown reason (this seems fairly constant regardless of time-control or FPS).
        /// </summary>
        /// <param name="kerbal">The kerbal on EVA.</param>
        /// <param name="realTime">The amount of real-time to manually update for.</param>
        IEnumerator ManuallyMoveKerbalEVACoroutine(KerbalEVA kerbal, Vector3 velocity, float realTime = 1f)
        {
            if (BDArmorySettings.DRAW_DEBUG_LABELS)
            {
                Debug.Log("[BDArmory.KerbalSafety]: Manually setting position of " + kerbal.vessel.vesselName + " for " + realTime + "s of real-time.");
            }
            if (!evaKerbalsToMonitor.Contains(kerbal))
            {
                evaKerbalsToMonitor.Add(kerbal);
            }
            var   gee                     = (Vector3)FlightGlobals.getGeeForceAtPosition(kerbal.transform.position);
            var   verticalSpeed           = Vector3.Dot(-gee.normalized, velocity);
            float verticalSpeedAdjustment = 0f;
            var   position                = kerbal.vessel.GetWorldPos3D();

            if (kerbal.vessel.radarAltitude + verticalSpeed * Time.fixedDeltaTime < 2f) // Crashed into terrain, explode upwards.
            {
                if (BDArmorySettings.DRAW_DEBUG_LABELS)
                {
                    verticalSpeedAdjustment = 3f * (float)gee.magnitude - verticalSpeed;
                }
                velocity  = Vector3.ProjectOnPlane(velocity, -gee.normalized) - 3f * (gee + UnityEngine.Random.onUnitSphere * 0.3f * gee.magnitude);
                position += (2f - (float)kerbal.vessel.radarAltitude) * -gee.normalized;
                kerbal.vessel.SetPosition(position); // Put the kerbal back at just above gound level.
                kerbal.vessel.Landed = false;
            }
            else
            {
                velocity += 1.5f * -(gee + UnityEngine.Random.onUnitSphere * 0.3f * gee.magnitude);
                if (BDArmorySettings.DRAW_DEBUG_LABELS)
                {
                    verticalSpeedAdjustment = 1.5f * (float)gee.magnitude;
                }
            }
            verticalSpeed = Vector3.Dot(-gee.normalized, velocity);
            kerbal.vessel.SetRotation(UnityEngine.Random.rotation);
            kerbal.vessel.rootPart.AddTorque(UnityEngine.Random.onUnitSphere * UnityEngine.Random.Range(1, 2));
            if (BDArmorySettings.DRAW_DEBUG_LABELS)
            {
                Debug.Log("[BDArmory.KerbalSafety]: Setting " + kerbal.vessel.vesselName + "'s position to " + position.ToString("0.00") + " (" + kerbal.vessel.GetWorldPos3D().ToString("0.00") + ", altitude: " + kerbal.vessel.radarAltitude.ToString("0.00") + ") and velocity to " + velocity.magnitude.ToString("0.00") + " (" + verticalSpeed.ToString("0.00") + "m/s vertically, adjusted by " + verticalSpeedAdjustment.ToString("0.00") + "m/s)");
            }
            var startTime = Time.realtimeSinceStartup;

            kerbal.vessel.rootPart.SetDetectCollisions(false);
            while (kerbal != null && kerbal.isActiveAndEnabled && kerbal.vessel != null && kerbal.vessel.isActiveAndEnabled && Time.realtimeSinceStartup - startTime < realTime)
            {
                // Note: 0.968f gives a reduction in speed to ~20% over 1s.
                if (verticalSpeed < 0f && kerbal.vessel.radarAltitude + verticalSpeed * (realTime - (Time.realtimeSinceStartup - startTime)) < 100f)
                {
                    velocity = velocity * 0.968f + gee * verticalSpeed / 10f * Time.fixedDeltaTime;
                    if (BDArmorySettings.DRAW_DEBUG_LABELS)
                    {
                        verticalSpeedAdjustment = Vector3.Dot(-gee.normalized, gee * verticalSpeed / 10f * Time.fixedDeltaTime);
                    }
                }
                else
                {
                    velocity = velocity * 0.968f + gee * Time.fixedDeltaTime;
                    if (BDArmorySettings.DRAW_DEBUG_LABELS)
                    {
                        verticalSpeedAdjustment = Vector3.Dot(-gee.normalized, gee * Time.fixedDeltaTime);
                    }
                }
                verticalSpeed = Vector3.Dot(-gee.normalized, velocity);
                position     += velocity * Time.fixedDeltaTime - FloatingOrigin.Offset;
                kerbal.vessel.IgnoreGForces(1);
                kerbal.vessel.IgnoreSpeed(1);
                kerbal.vessel.SetPosition(position);
                kerbal.vessel.SetWorldVelocity(velocity + Krakensbane.GetLastCorrection());
                yield return(new WaitForFixedUpdate());

                if (BDArmorySettings.DRAW_DEBUG_LABELS)
                {
                    Debug.Log("[BDArmory.KerbalSafety]: Setting " + kerbal.vessel.vesselName + "'s position to " + position.ToString("0.00") + " (" + kerbal.vessel.GetWorldPos3D().ToString("0.00") + ", altitude: " + kerbal.vessel.radarAltitude.ToString("0.00") + ") and velocity to " + velocity.magnitude.ToString("0.00") + " (" + kerbal.vessel.Velocity().magnitude.ToString("0.00") + ", " + verticalSpeed.ToString("0.00") + "m/s vertically, adjusted by " + verticalSpeedAdjustment.ToString("0.00") + "m/s)." + " (offset: " + !FloatingOrigin.Offset.IsZero() + ", frameVel: " + !Krakensbane.GetFrameVelocity().IsZero() + ")" + " " + Krakensbane.GetFrameVelocityV3f().ToString("0.0") + ", corr: " + Krakensbane.GetLastCorrection().ToString("0.0"));
                }
            }
            if (kerbal != null && kerbal.vessel != null)
            {
                kerbal.vessel.rootPart.SetDetectCollisions(true);
            }
            if (BDArmorySettings.DRAW_DEBUG_LABELS)
            {
                for (int count = 0; kerbal != null && kerbal.isActiveAndEnabled && kerbal.vessel != null && kerbal.vessel.isActiveAndEnabled && count < 10; ++count)
                {
                    yield return(new WaitForFixedUpdate());

                    Debug.Log("[BDArmory.KerbalSafety]: Tracking " + kerbal.vessel.vesselName + "'s position to " + kerbal.vessel.GetWorldPos3D().ToString("0.00") + " (altitude: " + kerbal.vessel.radarAltitude.ToString("0.00") + ") and velocity to " + kerbal.vessel.Velocity().magnitude.ToString("0.00") + " (" + kerbal.vessel.verticalSpeed.ToString("0.00") + "m/s vertically." + " (offset: " + !FloatingOrigin.Offset.IsZero() + ", frameVel: " + !Krakensbane.GetFrameVelocity().IsZero() + ")" + " " + Krakensbane.GetFrameVelocityV3f().ToString("0.0") + ", corr: " + Krakensbane.GetLastCorrection().ToString("0.0"));
                }
            }
        }