From 03455b54269c2b1ec072e6ef5ea47a980664a94a Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 9 Aug 2023 23:49:41 -0400 Subject: [PATCH 01/26] AddPhysics on planet allows it to be deorbited #194 --- .../Builder/General/RigidBodyBuilder.cs | 54 ++++++++++++++++--- .../Builder/Orbital/OrbitlineBuilder.cs | 12 ++++- NewHorizons/External/Modules/BaseModule.cs | 8 +++ NewHorizons/Handlers/PlanetCreationHandler.cs | 4 +- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index 9a0d5186..54d89cd5 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -1,15 +1,17 @@ +using NewHorizons.External; +using NewHorizons.External.Configs; using NewHorizons.Utility; +using NewHorizons.Utility.OWML; using UnityEngine; namespace NewHorizons.Builder.General { public static class RigidBodyBuilder { - public static OWRigidbody Make(GameObject body, float sphereOfInfluence) + public static OWRigidbody Make(GameObject body, float sphereOfInfluence, PlanetConfig config) { body.AddComponent()._bounds.radius = sphereOfInfluence; Rigidbody rigidBody = body.AddComponent(); - rigidBody.mass = 10000; rigidBody.drag = 0f; rigidBody.angularDrag = 0f; rigidBody.useGravity = false; @@ -17,18 +19,56 @@ namespace NewHorizons.Builder.General rigidBody.interpolation = RigidbodyInterpolation.None; rigidBody.collisionDetectionMode = CollisionDetectionMode.Discrete; - KinematicRigidbody kinematicRigidBody = body.AddComponent(); - OWRigidbody owRigidBody = body.AddComponent(); - owRigidBody._kinematicSimulation = true; owRigidBody._autoGenerateCenterOfMass = true; owRigidBody.SetIsTargetable(true); owRigidBody._maintainOriginalCenterOfMass = true; owRigidBody._rigidbody = rigidBody; - owRigidBody._kinematicRigidbody = kinematicRigidBody; owRigidBody._origParent = SearchUtilities.Find("SolarSystemRoot")?.transform; - owRigidBody.EnableKinematicSimulation(); + + KinematicRigidbody kinematicRigidBody = body.AddComponent(); + owRigidBody._kinematicRigidbody = kinematicRigidBody; + owRigidBody._kinematicSimulation = true; owRigidBody.MakeKinematic(); + owRigidBody.EnableKinematicSimulation(); + rigidBody.mass = 10000; + + if (config.Base.addPhysics) + { + // hack: make all mesh colliders convex + // triggers are already convex + // prints errors for non readable meshes but whatever + foreach (var meshCollider in body.GetComponentsInChildren(true)) + meshCollider.convex = true; + + var shape = body.AddComponent(); + shape._collisionMode = Shape.CollisionMode.Detector; + shape._layerMask = (int)(Shape.Layer.Default | Shape.Layer.Gravity); + shape._radius = config.Base.surfaceSize; + + var impactSensor = body.AddComponent(); + var audioSource = body.AddComponent(); + audioSource.maxDistance = 30; + audioSource.dopplerLevel = 0; + audioSource.rolloffMode = AudioRolloffMode.Custom; + audioSource.playOnAwake = false; + audioSource.spatialBlend = 1; + + var owAudioSource = body.AddComponent(); + owAudioSource._audioSource = audioSource; + owAudioSource._track = OWAudioMixer.TrackName.Environment; + + var objectImpactAudio = body.AddComponent(); + objectImpactAudio._minPitch = 0.4f; + objectImpactAudio._maxPitch = 0.6f; + objectImpactAudio._impactSensor = impactSensor; + + owRigidBody.MakeNonKinematic(); + owRigidBody.DisableKinematicSimulation(); + + // Should make this number changeable + Delay.FireOnNextUpdate(() => owRigidBody.SetMass(0.001f)); + } return owRigidBody; } diff --git a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs index 0ede52f2..fac2bfcf 100644 --- a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs +++ b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs @@ -17,7 +17,7 @@ namespace NewHorizons.Builder.Orbital if (_dottedLineMaterial == null || _lineMaterial == null) return null; - GameObject orbitGO = new GameObject("Orbit"); + var orbitGO = new GameObject("Orbit"); orbitGO.transform.parent = planetGO.transform; orbitGO.transform.localPosition = Vector3.zero; @@ -83,6 +83,16 @@ namespace NewHorizons.Builder.Orbital Delay.FireOnNextUpdate(orbitLine.InitializeLineRenderer); + // If the planet has physics and a regular orbit line, make sure that when it's bumped into the old orbit line vanishes + if (config.Base.addPhysics && !config.Orbit.trackingOrbitLine) + { + var impactSensor = planetGO.GetComponent(); + impactSensor.OnImpact += (ImpactData _) => + { + orbitGO.SetActive(false); + }; + } + return orbitLine; } } diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index cfab241e..03dbb51a 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -71,6 +71,14 @@ namespace NewHorizons.External.Modules /// [DefaultValue(0)] public int gravityVolumePriority = 0; + /// + /// Apply physics to this planet when you bump into it. Will have a spherical collider the size of surfaceSize. + /// For custom colliders they have to all be convex and you can leave surface size as 0. + /// This is meant for stuff like satellites which are relatively simple and can be de-orbited. + /// If you are using an orbit line but a tracking line, it will be removed when the planet is bumped in to. + /// + public bool addPhysics; + #region Obsolete [Obsolete("IsSatellite is deprecated, please use ShowMinimap instead")] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index ea235665..2b014cbf 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -348,7 +348,7 @@ namespace NewHorizons.Handlers const float sphereOfInfluence = 2000f; - var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence); + var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config); var ao = AstroObjectBuilder.Make(go, null, body.Config, false); var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence); @@ -423,7 +423,7 @@ namespace NewHorizons.Handlers var sphereOfInfluence = GetSphereOfInfluence(body); - var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence); + var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config); var ao = AstroObjectBuilder.Make(go, primaryBody, body.Config, false); var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence * 2f); From 39324e00b09b523e4f69bcb02ec8e846a5f09fab Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 10 Aug 2023 03:52:34 +0000 Subject: [PATCH 02/26] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 62a2069c..bb897a04 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -573,6 +573,10 @@ "description": "Optional. You can force this planet's gravity to be felt over other gravity/zero-gravity sources by increasing this number.", "format": "int32", "default": 0 + }, + "addPhysics": { + "type": "boolean", + "description": "Apply physics to this planet when you bump into it. Will have a spherical collider the size of surfaceSize. \nFor custom colliders they have to all be convex and you can leave surface size as 0.\nThis is meant for stuff like satellites which are relatively simple and can be de-orbited.\nIf you are using an orbit line but a tracking line, it will be removed when the planet is bumped in to." } } }, From 0bcaa3f7ef26fa7cbd670f3a8bb221a84da4fba0 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 10 Aug 2023 00:31:50 -0400 Subject: [PATCH 03/26] Add comments --- NewHorizons/Builder/General/RigidBodyBuilder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index 54d89cd5..5661d430 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -63,10 +63,14 @@ namespace NewHorizons.Builder.General objectImpactAudio._maxPitch = 0.6f; objectImpactAudio._impactSensor = impactSensor; + // For some reason when originally testing, not doing MakeKinematic caused the body to not move relative to the player character + // It seems that turning it on and then off makes it actually work properly owRigidBody.MakeNonKinematic(); owRigidBody.DisableKinematicSimulation(); - // Should make this number changeable + // Should make this number changeable, if anybody ever asks + // For some reason, setting this on the exact same frame as it is created doesn't work. + // I imagine something strange is happening on Awake/Start, hence the delay Delay.FireOnNextUpdate(() => owRigidBody.SetMass(0.001f)); } From caca976e0c1f097d70472e528f4f7057e4a82832 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 9 Aug 2023 21:34:16 -0700 Subject: [PATCH 04/26] unrelated to pr: put comments i meant to put before --- NewHorizons/Builder/Props/DetailBuilder.cs | 1 + NewHorizons/Builder/Props/ShuttleBuilder.cs | 1 + NewHorizons/Components/Stars/SunLightEffectsController.cs | 2 ++ 3 files changed, 4 insertions(+) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 6c762931..6a4cb798 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -259,6 +259,7 @@ namespace NewHorizons.Builder.Props // Not doing else if here because idk if any of the classes below implement ISectorGroup // Null check else shuttles controls break + // parent sector is always null before Awake so this code actually never runs lol if (component is Sector s && s.GetParentSector() != null && !existingSectors.Contains(s.GetParentSector())) { s.SetParentSector(sector); diff --git a/NewHorizons/Builder/Props/ShuttleBuilder.cs b/NewHorizons/Builder/Props/ShuttleBuilder.cs index 06d8dabb..93bb4e98 100644 --- a/NewHorizons/Builder/Props/ShuttleBuilder.cs +++ b/NewHorizons/Builder/Props/ShuttleBuilder.cs @@ -52,6 +52,7 @@ namespace NewHorizons.Builder.Props neutralSlot._attractive = true; neutralSlot._muteAudio = true; nhShuttleController._neutralSlot = neutralSlot; + // TODO: at some point delay rigidbody parenting so we dont have to find orb via references. mainly to fix orbs on existing details _orbPrefab = shuttleController._orb.gameObject?.InstantiateInactive()?.Rename("Prefab_QM_Shuttle_InterfaceOrbSmall")?.DontDestroyOnLoad(); nhShuttleController._orb = _orbPrefab.GetComponent(); nhShuttleController._orb._sector = nhShuttleController._interiorSector; diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs index 8c3798bf..a5645472 100644 --- a/NewHorizons/Components/Stars/SunLightEffectsController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -195,6 +195,8 @@ namespace NewHorizons.Components.Stars // Some effects use Locator.GetSunTransform so hopefully its fine to change it Locator._sunTransform = transform; + + // TODO?: maybe also turn of star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on } } } From 7a5630bc0e93dad7395633bc0bcd2f06b4223af9 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 10 Aug 2023 00:54:31 -0400 Subject: [PATCH 05/26] Fix default system override #687 --- NewHorizons/Main.cs | 48 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index f2d5c7e7..6e5342e4 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -116,12 +116,12 @@ namespace NewHorizons else if (Debug) NHLogger.UpdateLogLevel(NHLogger.LogType.Log); else NHLogger.UpdateLogLevel(NHLogger.LogType.Error); + var oldDefaultSystemOverride = _defaultSystemOverride; _defaultSystemOverride = config.GetSettingsValue("Default System Override"); - - // Else it doesn't get set idk - if (currentScene == "TitleScreen" && SystemDict.ContainsKey(_defaultSystemOverride)) + if (oldDefaultSystemOverride != _defaultSystemOverride) { - _currentStarSystem = _defaultSystemOverride; + ResetCurrentStarSystem(); + NHLogger.Log($"Changed default star system override to {_defaultSystemOverride}"); } var wasUsingCustomTitleScreen = _useCustomTitleScreen; @@ -553,17 +553,7 @@ namespace NewHorizons } else { - // Reset back to original solar system after going to main menu. - // If the override is a valid system then we go there - if (SystemDict.ContainsKey(_defaultSystemOverride)) - { - _currentStarSystem = _defaultSystemOverride; - IsWarpingFromShip = true; // always do this else sometimes the spawn gets messed up - } - else - { - _currentStarSystem = _defaultStarSystem; - } + ResetCurrentStarSystem(); } } @@ -614,7 +604,7 @@ namespace NewHorizons if (starSystemName != "SolarSystem") { SetDefaultSystem(starSystemName); - _currentStarSystem = starSystemName; + _currentStarSystem = DefaultStarSystem; } } @@ -903,15 +893,23 @@ namespace NewHorizons { if (SystemDict[_currentStarSystem].Config.respawnHere) return; - // If the override is a valid system then we go there - if (SystemDict.ContainsKey(_defaultSystemOverride)) - { - _currentStarSystem = _defaultSystemOverride; - } - else - { - _currentStarSystem = _defaultStarSystem; - } + ResetCurrentStarSystem(); + } + } + + private void ResetCurrentStarSystem() + { + if (SystemDict.ContainsKey(_defaultSystemOverride)) + { + _currentStarSystem = _defaultSystemOverride; + + // Sometimes the override will not support spawning regularly, so always warp in + IsWarpingFromShip = true; + } + else + { + _currentStarSystem = _defaultStarSystem; + IsWarpingFromShip = false; } } #endregion Change star system From 2914856c74565b324f01b8f4ea478d79acf761b3 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 10 Aug 2023 00:59:40 -0400 Subject: [PATCH 06/26] Remove and sort using --- NewHorizons/Main.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 6e5342e4..2906f9be 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -3,8 +3,10 @@ using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Body; using NewHorizons.Builder.General; using NewHorizons.Builder.Props; +using NewHorizons.Builder.Props.Audio; using NewHorizons.Builder.Props.TranslatorText; using NewHorizons.Components.Fixers; +using NewHorizons.Components.Ship; using NewHorizons.Components.SizeControllers; using NewHorizons.External; using NewHorizons.External.Configs; @@ -14,9 +16,11 @@ using NewHorizons.OtherMods.MenuFramework; using NewHorizons.OtherMods.OWRichPresence; using NewHorizons.OtherMods.VoiceActing; using NewHorizons.Utility; +using NewHorizons.Utility.DebugTools; +using NewHorizons.Utility.DebugTools.Menu; using NewHorizons.Utility.Files; -using NewHorizons.Utility.OWML; using NewHorizons.Utility.OuterWilds; +using NewHorizons.Utility.OWML; using OWML.Common; using OWML.ModHelper; using OWML.Utils; @@ -29,12 +33,6 @@ using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; -using NewHorizons.Utility.DebugTools; -using NewHorizons.Utility.DebugTools.Menu; -using NewHorizons.Components.Ship; -using NewHorizons.Builder.Props.Audio; -using Epic.OnlineServices; - namespace NewHorizons { From 24482174f19595c69007232b3badeedbd7d17db3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 00:11:50 -0700 Subject: [PATCH 07/26] addphysics: set angular velocity too --- NewHorizons/Components/AddPhysics.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 6f987255..9576e20b 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -73,6 +73,7 @@ public class AddPhysics : MonoBehaviour transform.parent = bodyGo.transform; owRigidbody.SetMass(Mass); owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position)); + owRigidbody.SetAngularVelocity(parentBody.GetAngularVelocity()); // #536 - Physics objects in bramble dimensions not disabled on load // sectors wait 3 frames and then call OnSectorOccupantsUpdated From d735e65032476967764dcec2015fc81bdef00574 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 14:09:08 -0700 Subject: [PATCH 08/26] testing --- NewHorizons/Components/AddPhysics.cs | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 9576e20b..963a5bef 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,6 +1,7 @@ using NewHorizons.Utility.OuterWilds; using System.Collections; using UnityEngine; +using UnityEngine.InputSystem; namespace NewHorizons.Components; @@ -19,11 +20,16 @@ public class AddPhysics : MonoBehaviour "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; + private OWRigidbody parentBody; + private OWRigidbody owRigidbody; + private IEnumerator Start() { yield return new WaitForSeconds(.1f); - var parentBody = GetComponentInParent(); + parentBody = GetComponentInParent(); + + // yield return new WaitUntil(() => Keyboard.current.lKey.isPressed); // hack: make all mesh colliders convex // triggers are already convex @@ -37,8 +43,10 @@ public class AddPhysics : MonoBehaviour bodyGo.transform.position = transform.position; bodyGo.transform.rotation = transform.rotation; - var owRigidbody = bodyGo.AddComponent(); + owRigidbody = bodyGo.AddComponent(); owRigidbody._simulateInSector = Sector; + // owRigidbody._autoGenerateCenterOfMass = false; + // owRigidbody._centerOfMass = owRigidbody.transform.InverseTransformPoint(parentBody.GetPosition()); bodyGo.layer = Layer.PhysicalDetector; bodyGo.tag = "DynamicPropDetector"; @@ -72,8 +80,7 @@ public class AddPhysics : MonoBehaviour transform.parent = bodyGo.transform; owRigidbody.SetMass(Mass); - owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position)); - owRigidbody.SetAngularVelocity(parentBody.GetAngularVelocity()); + owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); // #536 - Physics objects in bramble dimensions not disabled on load // sectors wait 3 frames and then call OnSectorOccupantsUpdated @@ -82,6 +89,8 @@ public class AddPhysics : MonoBehaviour if (owRigidbody._simulateInSector != null) owRigidbody.OnSectorOccupantsUpdated(); + yield return new WaitUntil(() => Keyboard.current.kKey.isPressed); + Destroy(this); } @@ -89,4 +98,16 @@ public class AddPhysics : MonoBehaviour { Gizmos.DrawWireSphere(transform.position, Radius); } + + private void OnRenderObject() + { + Popcron.Gizmos.Sphere(transform.position, Radius); + Popcron.Gizmos.Line(transform.position, parentBody.GetPosition()); + Popcron.Gizmos.Line(transform.position, owRigidbody.GetWorldCenterOfMass()); + } + + private void FixedUpdate() + { + // owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); + } } From c8eb55f506949f8f2ce2e607a2fbbdf9ffb53789 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 14:32:24 -0700 Subject: [PATCH 09/26] mucho hacks --- NewHorizons/Components/AddPhysics.cs | 69 ++++++++++++++++++---------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 963a5bef..a67d7afc 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,7 +1,6 @@ using NewHorizons.Utility.OuterWilds; using System.Collections; using UnityEngine; -using UnityEngine.InputSystem; namespace NewHorizons.Components; @@ -20,16 +19,18 @@ public class AddPhysics : MonoBehaviour "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; - private OWRigidbody parentBody; - private OWRigidbody owRigidbody; + private OWRigidbody _parentBody; + private OWRigidbody _body; + private ImpactSensor _impactSensor; + private bool _maintainVelocity; + private Vector3 _centerOfMass; private IEnumerator Start() { - yield return new WaitForSeconds(.1f); + // detectors dont detect unless we wait for some reason + yield return new WaitForSeconds(10f); - parentBody = GetComponentInParent(); - - // yield return new WaitUntil(() => Keyboard.current.lKey.isPressed); + _parentBody = GetComponentInParent(); // hack: make all mesh colliders convex // triggers are already convex @@ -43,10 +44,10 @@ public class AddPhysics : MonoBehaviour bodyGo.transform.position = transform.position; bodyGo.transform.rotation = transform.rotation; - owRigidbody = bodyGo.AddComponent(); - owRigidbody._simulateInSector = Sector; - // owRigidbody._autoGenerateCenterOfMass = false; - // owRigidbody._centerOfMass = owRigidbody.transform.InverseTransformPoint(parentBody.GetPosition()); + _body = bodyGo.AddComponent(); + _body._simulateInSector = Sector; + _body._autoGenerateCenterOfMass = false; + _body._centerOfMass = _body.transform.InverseTransformPoint(_parentBody.GetWorldCenterOfMass()); bodyGo.layer = Layer.PhysicalDetector; bodyGo.tag = "DynamicPropDetector"; @@ -61,7 +62,7 @@ public class AddPhysics : MonoBehaviour fluidDetector._buoyancy = Locator.GetProbe().GetOWRigidbody()._attachedFluidDetector._buoyancy; fluidDetector._splashEffects = Locator.GetProbe().GetOWRigidbody()._attachedFluidDetector._splashEffects; - var impactSensor = bodyGo.AddComponent(); + _impactSensor = bodyGo.AddComponent(); var audioSource = bodyGo.AddComponent(); audioSource.maxDistance = 30; audioSource.dopplerLevel = 0; @@ -74,23 +75,46 @@ public class AddPhysics : MonoBehaviour var objectImpactAudio = bodyGo.AddComponent(); objectImpactAudio._minPitch = 0.4f; objectImpactAudio._maxPitch = 0.6f; - objectImpactAudio._impactSensor = impactSensor; + objectImpactAudio._impactSensor = _impactSensor; bodyGo.SetActive(true); transform.parent = bodyGo.transform; - owRigidbody.SetMass(Mass); - owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); + _body.SetMass(Mass); + _body.SetVelocity(_parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); + _body.SetAngularVelocity(_parentBody.GetAngularVelocity()); + // hack: make center of mass at the parent body so it doesn't drift on rotating body + // _centerOfMass = _body.GetCenterOfMass(); + // _body.SetCenterOfMass(_body.transform.InverseTransformPoint(_parentBody.GetWorldCenterOfMass())); + // _impactSensor.OnImpact += OnImpact; // #536 - Physics objects in bramble dimensions not disabled on load // sectors wait 3 frames and then call OnSectorOccupantsUpdated // however we wait .1 real seconds which is longer // so we have to manually call this - if (owRigidbody._simulateInSector != null) - owRigidbody.OnSectorOccupantsUpdated(); + if (_body._simulateInSector != null) + _body.OnSectorOccupantsUpdated(); - yield return new WaitUntil(() => Keyboard.current.kKey.isPressed); + // it drifts otherwise for some reason + _maintainVelocity = true; + yield return new WaitForSeconds(10f); + _maintainVelocity = false; + } + private void FixedUpdate() + { + if (_maintainVelocity) + { + _body.SetVelocity(_parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); + _body.SetAngularVelocity(_parentBody.GetAngularVelocity()); + } + } + + private void OnImpact(ImpactData impact) + { + // revert it back to normal + _body.SetCenterOfMass(_centerOfMass); + _impactSensor.OnImpact -= OnImpact; Destroy(this); } @@ -102,12 +126,7 @@ public class AddPhysics : MonoBehaviour private void OnRenderObject() { Popcron.Gizmos.Sphere(transform.position, Radius); - Popcron.Gizmos.Line(transform.position, parentBody.GetPosition()); - Popcron.Gizmos.Line(transform.position, owRigidbody.GetWorldCenterOfMass()); - } - - private void FixedUpdate() - { - // owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); + if (_body) Popcron.Gizmos.Line(transform.position, _body.GetWorldCenterOfMass(), Color.red); + if (_parentBody) Popcron.Gizmos.Line(transform.position, _parentBody.GetWorldCenterOfMass(), Color.green); } } From 4c60dcc0f88178c26847a4404b9f932f8739467d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 16:31:08 -0700 Subject: [PATCH 10/26] remove hacks. add suspend until impact --- NewHorizons/Builder/Props/DetailBuilder.cs | 2 + NewHorizons/Components/AddPhysics.cs | 53 +++++++------------ .../External/Modules/Props/DetailInfo.cs | 5 ++ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 6a4cb798..94d91f7f 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -221,6 +221,8 @@ namespace NewHorizons.Builder.Props addPhysics.Sector = sector; addPhysics.Mass = detail.physicsMass; addPhysics.Radius = detail.physicsRadius; + addPhysics.SuspendUntilImpact = detail.physicsSuspendUntilImpact; + addPhysics.KeepLoaded = detail.keepLoaded; } if (!string.IsNullOrEmpty(detail.activationCondition)) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index a67d7afc..9be3bafe 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,4 +1,5 @@ using NewHorizons.Utility.OuterWilds; +using System; using System.Collections; using UnityEngine; @@ -18,19 +19,21 @@ public class AddPhysics : MonoBehaviour [Tooltip("The radius that the added sphere collider will use for physics collision.\n" + "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; + [Tooltip("If true, this detail will stay still until it bumps something.")] + public bool SuspendUntilImpact; + + [NonSerialized] + public bool KeepLoaded; - private OWRigidbody _parentBody; private OWRigidbody _body; private ImpactSensor _impactSensor; - private bool _maintainVelocity; - private Vector3 _centerOfMass; private IEnumerator Start() { // detectors dont detect unless we wait for some reason - yield return new WaitForSeconds(10f); + yield return new WaitForSeconds(.1f); - _parentBody = GetComponentInParent(); + var parentBody = GetComponentInParent(); // hack: make all mesh colliders convex // triggers are already convex @@ -45,9 +48,7 @@ public class AddPhysics : MonoBehaviour bodyGo.transform.rotation = transform.rotation; _body = bodyGo.AddComponent(); - _body._simulateInSector = Sector; - _body._autoGenerateCenterOfMass = false; - _body._centerOfMass = _body.transform.InverseTransformPoint(_parentBody.GetWorldCenterOfMass()); + _body._simulateInSector = KeepLoaded ? null : Sector; bodyGo.layer = Layer.PhysicalDetector; bodyGo.tag = "DynamicPropDetector"; @@ -81,12 +82,8 @@ public class AddPhysics : MonoBehaviour transform.parent = bodyGo.transform; _body.SetMass(Mass); - _body.SetVelocity(_parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); - _body.SetAngularVelocity(_parentBody.GetAngularVelocity()); - // hack: make center of mass at the parent body so it doesn't drift on rotating body - // _centerOfMass = _body.GetCenterOfMass(); - // _body.SetCenterOfMass(_body.transform.InverseTransformPoint(_parentBody.GetWorldCenterOfMass())); - // _impactSensor.OnImpact += OnImpact; + _body.SetVelocity(parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); + _body.SetAngularVelocity(parentBody.GetAngularVelocity()); // #536 - Physics objects in bramble dimensions not disabled on load // sectors wait 3 frames and then call OnSectorOccupantsUpdated @@ -95,25 +92,20 @@ public class AddPhysics : MonoBehaviour if (_body._simulateInSector != null) _body.OnSectorOccupantsUpdated(); - // it drifts otherwise for some reason - _maintainVelocity = true; - yield return new WaitForSeconds(10f); - _maintainVelocity = false; - } - - private void FixedUpdate() - { - if (_maintainVelocity) + if (SuspendUntilImpact) { - _body.SetVelocity(_parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); - _body.SetAngularVelocity(_parentBody.GetAngularVelocity()); + _body.Suspend(); + _impactSensor.OnImpact += OnImpact; + } + else + { + Destroy(this); } } private void OnImpact(ImpactData impact) { - // revert it back to normal - _body.SetCenterOfMass(_centerOfMass); + _body.Unsuspend(); _impactSensor.OnImpact -= OnImpact; Destroy(this); } @@ -122,11 +114,4 @@ public class AddPhysics : MonoBehaviour { Gizmos.DrawWireSphere(transform.position, Radius); } - - private void OnRenderObject() - { - Popcron.Gizmos.Sphere(transform.position, Radius); - if (_body) Popcron.Gizmos.Line(transform.position, _body.GetWorldCenterOfMass(), Color.red); - if (_parentBody) Popcron.Gizmos.Line(transform.position, _parentBody.GetWorldCenterOfMass(), Color.green); - } } diff --git a/NewHorizons/External/Modules/Props/DetailInfo.cs b/NewHorizons/External/Modules/Props/DetailInfo.cs index a6cb6592..f22ed8bd 100644 --- a/NewHorizons/External/Modules/Props/DetailInfo.cs +++ b/NewHorizons/External/Modules/Props/DetailInfo.cs @@ -75,6 +75,11 @@ namespace NewHorizons.External.Modules.Props /// [DefaultValue(1f)] public float physicsRadius = 1f; + /// + /// If true, this detail will stay still until it bumps something. + /// + public bool physicsSuspendUntilImpact; + /// /// Set to true if this object's lighting should ignore the effects of sunlight /// From 6ab184ef079b16d5c5e4702f27b6ad2c0e7d85e4 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:31:50 -0700 Subject: [PATCH 11/26] copy paste blah --- NewHorizons/Components/AddPhysics.cs | 60 +++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 9be3bafe..5f3183a1 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -30,6 +30,8 @@ public class AddPhysics : MonoBehaviour private IEnumerator Start() { + SuspendUntilImpact = true; + // detectors dont detect unless we wait for some reason yield return new WaitForSeconds(.1f); @@ -94,7 +96,8 @@ public class AddPhysics : MonoBehaviour if (SuspendUntilImpact) { - _body.Suspend(); + // suspend disables colliders, so have to use copy-pasted version + Suspend(); _impactSensor.OnImpact += OnImpact; } else @@ -103,6 +106,61 @@ public class AddPhysics : MonoBehaviour } } + #region copy-pasted from OWRigidbody + + private void Suspend() + { + if (!_body._suspended) + { + if (_body._origParentBody != null) + { + Suspend(_body._origParent, _body._origParentBody); + return; + } + if (_body._simulateInSector != null) + { + Suspend(_body._simulateInSector.GetOWRigidbody()); + return; + } + Debug.Log("Unable to suspend : " + _body.gameObject.name); + } + } + + private void Suspend(OWRigidbody suspensionBody) + { + _body.Suspend(suspensionBody.transform, suspensionBody); + } + + private void Suspend(Transform suspensionParent, OWRigidbody suspensionBody) + { + if (!_body._suspended || _body._unsuspendNextUpdate) + { + _body._suspensionBody = suspensionBody; + Vector3 vector = _body.GetVelocity() - suspensionBody.GetPointVelocity(_body._transform.position); + _body._cachedRelativeVelocity = suspensionBody.transform.InverseTransformDirection(vector); + _body._cachedAngularVelocity = (_body.RunningKinematicSimulation() ? _body._kinematicRigidbody.angularVelocity : _body._rigidbody.angularVelocity); + _body.enabled = false; + _body._offsetApplier.enabled = false; + if (_body.RunningKinematicSimulation()) + { + _body._kinematicRigidbody.enabled = false; + } + else + { + _body.MakeKinematic(); + } + _body._transform.parent = suspensionParent; + _body._suspended = true; + _body._unsuspendNextUpdate = false; + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } + } + } + + #endregion + private void OnImpact(ImpactData impact) { _body.Unsuspend(); From a968308597ae035d01413af8527425347d71621b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:39:00 -0700 Subject: [PATCH 12/26] copy without killing you --- NewHorizons/Components/AddPhysics.cs | 64 +++------------------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 5f3183a1..635ed6d1 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -96,8 +96,13 @@ public class AddPhysics : MonoBehaviour if (SuspendUntilImpact) { - // suspend disables colliders, so have to use copy-pasted version - Suspend(); + // copied from OWRigidbody.Suspend + _body._suspensionBody = parentBody; + _body.MakeKinematic(); + _body._transform.parent = parentBody.transform; + _body._suspended = true; + _body._unsuspendNextUpdate = false; + _impactSensor.OnImpact += OnImpact; } else @@ -105,61 +110,6 @@ public class AddPhysics : MonoBehaviour Destroy(this); } } - - #region copy-pasted from OWRigidbody - - private void Suspend() - { - if (!_body._suspended) - { - if (_body._origParentBody != null) - { - Suspend(_body._origParent, _body._origParentBody); - return; - } - if (_body._simulateInSector != null) - { - Suspend(_body._simulateInSector.GetOWRigidbody()); - return; - } - Debug.Log("Unable to suspend : " + _body.gameObject.name); - } - } - - private void Suspend(OWRigidbody suspensionBody) - { - _body.Suspend(suspensionBody.transform, suspensionBody); - } - - private void Suspend(Transform suspensionParent, OWRigidbody suspensionBody) - { - if (!_body._suspended || _body._unsuspendNextUpdate) - { - _body._suspensionBody = suspensionBody; - Vector3 vector = _body.GetVelocity() - suspensionBody.GetPointVelocity(_body._transform.position); - _body._cachedRelativeVelocity = suspensionBody.transform.InverseTransformDirection(vector); - _body._cachedAngularVelocity = (_body.RunningKinematicSimulation() ? _body._kinematicRigidbody.angularVelocity : _body._rigidbody.angularVelocity); - _body.enabled = false; - _body._offsetApplier.enabled = false; - if (_body.RunningKinematicSimulation()) - { - _body._kinematicRigidbody.enabled = false; - } - else - { - _body.MakeKinematic(); - } - _body._transform.parent = suspensionParent; - _body._suspended = true; - _body._unsuspendNextUpdate = false; - if (!Physics.autoSyncTransforms) - { - Physics.SyncTransforms(); - } - } - } - - #endregion private void OnImpact(ImpactData impact) { From fb1085e7b98852e8107a1b81d5d888496c289a23 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:40:47 -0700 Subject: [PATCH 13/26] better doc --- NewHorizons/Components/AddPhysics.cs | 2 +- NewHorizons/External/Modules/Props/DetailInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 635ed6d1..aa2f135b 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -19,7 +19,7 @@ public class AddPhysics : MonoBehaviour [Tooltip("The radius that the added sphere collider will use for physics collision.\n" + "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; - [Tooltip("If true, this detail will stay still until it bumps something.")] + [Tooltip("If true, this detail will stay still until it touches something.")] public bool SuspendUntilImpact; [NonSerialized] diff --git a/NewHorizons/External/Modules/Props/DetailInfo.cs b/NewHorizons/External/Modules/Props/DetailInfo.cs index f22ed8bd..100b11e5 100644 --- a/NewHorizons/External/Modules/Props/DetailInfo.cs +++ b/NewHorizons/External/Modules/Props/DetailInfo.cs @@ -76,7 +76,7 @@ namespace NewHorizons.External.Modules.Props [DefaultValue(1f)] public float physicsRadius = 1f; /// - /// If true, this detail will stay still until it bumps something. + /// If true, this detail will stay still until it touches something. /// public bool physicsSuspendUntilImpact; From a1c3ead3593ad594e1689c428fc191960af97f7b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:40:52 -0700 Subject: [PATCH 14/26] format --- NewHorizons/Components/AddPhysics.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index aa2f135b..a46256f4 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -31,7 +31,7 @@ public class AddPhysics : MonoBehaviour private IEnumerator Start() { SuspendUntilImpact = true; - + // detectors dont detect unless we wait for some reason yield return new WaitForSeconds(.1f); @@ -102,7 +102,7 @@ public class AddPhysics : MonoBehaviour _body._transform.parent = parentBody.transform; _body._suspended = true; _body._unsuspendNextUpdate = false; - + _impactSensor.OnImpact += OnImpact; } else @@ -110,7 +110,7 @@ public class AddPhysics : MonoBehaviour Destroy(this); } } - + private void OnImpact(ImpactData impact) { _body.Unsuspend(); From dfc0ee88360fba711f0900c91c93d24bc23b8af2 Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 11 Aug 2023 00:41:45 +0000 Subject: [PATCH 15/26] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 62a2069c..0ddb19d5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1339,6 +1339,10 @@ "format": "float", "default": 1.0 }, + "physicsSuspendUntilImpact": { + "type": "boolean", + "description": "If true, this detail will stay still until it bumps something." + }, "ignoreSun": { "type": "boolean", "description": "Set to true if this object's lighting should ignore the effects of sunlight" From edeeb6f9eccad38dea0411fd3568a514b6574cbf Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:43:19 -0700 Subject: [PATCH 16/26] remove test code for SuspendUntilImpact --- NewHorizons/Components/AddPhysics.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index a46256f4..1169b05e 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -30,8 +30,6 @@ public class AddPhysics : MonoBehaviour private IEnumerator Start() { - SuspendUntilImpact = true; - // detectors dont detect unless we wait for some reason yield return new WaitForSeconds(.1f); From 41285823ca75ea692928db8ea307026a4a95a27e Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:45:03 -0700 Subject: [PATCH 17/26] docs and comments --- NewHorizons/Builder/Props/ShuttleBuilder.cs | 2 +- NewHorizons/Components/AddPhysics.cs | 3 ++- NewHorizons/Components/Stars/SunLightEffectsController.cs | 2 +- NewHorizons/External/Modules/Props/DetailInfo.cs | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Props/ShuttleBuilder.cs b/NewHorizons/Builder/Props/ShuttleBuilder.cs index 93bb4e98..f855990d 100644 --- a/NewHorizons/Builder/Props/ShuttleBuilder.cs +++ b/NewHorizons/Builder/Props/ShuttleBuilder.cs @@ -52,7 +52,7 @@ namespace NewHorizons.Builder.Props neutralSlot._attractive = true; neutralSlot._muteAudio = true; nhShuttleController._neutralSlot = neutralSlot; - // TODO: at some point delay rigidbody parenting so we dont have to find orb via references. mainly to fix orbs on existing details + // TODO: at some point delay rigidbody parenting so we dont have to find orb via references. mainly to fix orbs on existing details and rafts not rotating with planets _orbPrefab = shuttleController._orb.gameObject?.InstantiateInactive()?.Rename("Prefab_QM_Shuttle_InterfaceOrbSmall")?.DontDestroyOnLoad(); nhShuttleController._orb = _orbPrefab.GetComponent(); nhShuttleController._orb._sector = nhShuttleController._interiorSector; diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 1169b05e..330e0269 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -19,7 +19,8 @@ public class AddPhysics : MonoBehaviour [Tooltip("The radius that the added sphere collider will use for physics collision.\n" + "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; - [Tooltip("If true, this detail will stay still until it touches something.")] + [Tooltip("If true, this detail will stay still until it touches something.\n" + + "Good for zero-g props.")] public bool SuspendUntilImpact; [NonSerialized] diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs index a5645472..6d26808e 100644 --- a/NewHorizons/Components/Stars/SunLightEffectsController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -196,7 +196,7 @@ namespace NewHorizons.Components.Stars // Some effects use Locator.GetSunTransform so hopefully its fine to change it Locator._sunTransform = transform; - // TODO?: maybe also turn of star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on + // TODO?: maybe also turn off star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on } } } diff --git a/NewHorizons/External/Modules/Props/DetailInfo.cs b/NewHorizons/External/Modules/Props/DetailInfo.cs index 100b11e5..fddc0239 100644 --- a/NewHorizons/External/Modules/Props/DetailInfo.cs +++ b/NewHorizons/External/Modules/Props/DetailInfo.cs @@ -77,6 +77,7 @@ namespace NewHorizons.External.Modules.Props /// /// If true, this detail will stay still until it touches something. + /// Good for zero-g props. /// public bool physicsSuspendUntilImpact; From 5f5c971518e37c803d72f3952c2fa23f3033237b Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 11 Aug 2023 00:47:52 +0000 Subject: [PATCH 18/26] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 0ddb19d5..1b21b66f 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1341,7 +1341,7 @@ }, "physicsSuspendUntilImpact": { "type": "boolean", - "description": "If true, this detail will stay still until it bumps something." + "description": "If true, this detail will stay still until it touches something.\nGood for zero-g props." }, "ignoreSun": { "type": "boolean", From 2a67040fb1cd62c96c25717937a4dc491c10aa3c Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 17:47:51 -0700 Subject: [PATCH 19/26] default value --- NewHorizons/External/Modules/Props/DetailInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/Props/DetailInfo.cs b/NewHorizons/External/Modules/Props/DetailInfo.cs index fddc0239..48b3b125 100644 --- a/NewHorizons/External/Modules/Props/DetailInfo.cs +++ b/NewHorizons/External/Modules/Props/DetailInfo.cs @@ -79,7 +79,7 @@ namespace NewHorizons.External.Modules.Props /// If true, this detail will stay still until it touches something. /// Good for zero-g props. /// - public bool physicsSuspendUntilImpact; + [DefaultValue(false)] public bool physicsSuspendUntilImpact = false; /// /// Set to true if this object's lighting should ignore the effects of sunlight From 9899f38dfd6329a6896f66518cd0ea05e2677232 Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 11 Aug 2023 00:50:59 +0000 Subject: [PATCH 20/26] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 1b21b66f..a85813be 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1341,7 +1341,8 @@ }, "physicsSuspendUntilImpact": { "type": "boolean", - "description": "If true, this detail will stay still until it touches something.\nGood for zero-g props." + "description": "If true, this detail will stay still until it touches something.\nGood for zero-g props.", + "default": false }, "ignoreSun": { "type": "boolean", From fee49a846824439b85a121e3a60e38ea95c3eb89 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 18:40:09 -0700 Subject: [PATCH 21/26] probe impulse --- NewHorizons/Components/AddPhysics.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 330e0269..eab65750 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -31,6 +31,9 @@ public class AddPhysics : MonoBehaviour private IEnumerator Start() { + SuspendUntilImpact = true; + Mass = .001f; + // detectors dont detect unless we wait for some reason yield return new WaitForSeconds(.1f); @@ -103,6 +106,7 @@ public class AddPhysics : MonoBehaviour _body._unsuspendNextUpdate = false; _impactSensor.OnImpact += OnImpact; + Locator.GetProbe().OnAnchorProbe += OnAnchorProbe; } else { @@ -112,11 +116,30 @@ public class AddPhysics : MonoBehaviour private void OnImpact(ImpactData impact) { - _body.Unsuspend(); + _body.UnsuspendImmediate(false); _impactSensor.OnImpact -= OnImpact; + Locator.GetProbe().OnAnchorProbe -= OnAnchorProbe; Destroy(this); } + private void OnAnchorProbe() + { + var attachedOWRigidbody = Locator.GetProbe().GetAttachedOWRigidbody(true); + if (attachedOWRigidbody == _body) + { + OnImpact(null); + + // copied from ProbeAnchor.AnchorToObject + var _probeBody = Locator.GetProbe().GetOWRigidbody(); + var hitPoint = _probeBody.GetWorldCenterOfMass(); + if (attachedOWRigidbody.GetMass() < 100f) + { + Vector3 vector = _probeBody.GetVelocity() - attachedOWRigidbody.GetPointVelocity(_probeBody.GetPosition()); + attachedOWRigidbody.GetRigidbody().AddForceAtPosition(vector.normalized * 0.005f, hitPoint, ForceMode.Impulse); + } + } + } + private void OnDrawGizmosSelected() { Gizmos.DrawWireSphere(transform.position, Radius); From 8363bc6f6add04c260c1f83db6e0041570521e3f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 18:44:07 -0700 Subject: [PATCH 22/26] grr i did it again --- NewHorizons/Components/AddPhysics.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index eab65750..d298d5c8 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -31,9 +31,6 @@ public class AddPhysics : MonoBehaviour private IEnumerator Start() { - SuspendUntilImpact = true; - Mass = .001f; - // detectors dont detect unless we wait for some reason yield return new WaitForSeconds(.1f); From 8612dde4244f861630623438c8baa428450a27ae Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 18:49:44 -0700 Subject: [PATCH 23/26] make it not targetable --- NewHorizons/Components/AddPhysics.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index d298d5c8..f148e560 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -101,6 +101,9 @@ public class AddPhysics : MonoBehaviour _body._transform.parent = parentBody.transform; _body._suspended = true; _body._unsuspendNextUpdate = false; + + // match velocity doesnt work so just make it not targetable + _body.SetIsTargetable(false); _impactSensor.OnImpact += OnImpact; Locator.GetProbe().OnAnchorProbe += OnAnchorProbe; @@ -114,6 +117,7 @@ public class AddPhysics : MonoBehaviour private void OnImpact(ImpactData impact) { _body.UnsuspendImmediate(false); + _body.SetIsTargetable(true); _impactSensor.OnImpact -= OnImpact; Locator.GetProbe().OnAnchorProbe -= OnAnchorProbe; Destroy(this); From 9a2302a66b9c545097968095c4a9fad5ce4dd156 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 18:59:41 -0700 Subject: [PATCH 24/26] xen suggestions --- NewHorizons/Builder/Props/DetailBuilder.cs | 3 +-- NewHorizons/Components/AddPhysics.cs | 19 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 94d91f7f..622cdd82 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -218,11 +218,10 @@ namespace NewHorizons.Builder.Props if (detail.hasPhysics) { var addPhysics = prop.AddComponent(); - addPhysics.Sector = sector; + addPhysics.Sector = detail.keepLoaded ? null : sector; addPhysics.Mass = detail.physicsMass; addPhysics.Radius = detail.physicsRadius; addPhysics.SuspendUntilImpact = detail.physicsSuspendUntilImpact; - addPhysics.KeepLoaded = detail.keepLoaded; } if (!string.IsNullOrEmpty(detail.activationCondition)) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index f148e560..c7671a50 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,5 +1,4 @@ using NewHorizons.Utility.OuterWilds; -using System; using System.Collections; using UnityEngine; @@ -23,9 +22,6 @@ public class AddPhysics : MonoBehaviour "Good for zero-g props.")] public bool SuspendUntilImpact; - [NonSerialized] - public bool KeepLoaded; - private OWRigidbody _body; private ImpactSensor _impactSensor; @@ -49,7 +45,7 @@ public class AddPhysics : MonoBehaviour bodyGo.transform.rotation = transform.rotation; _body = bodyGo.AddComponent(); - _body._simulateInSector = KeepLoaded ? null : Sector; + _body._simulateInSector = Sector; bodyGo.layer = Layer.PhysicalDetector; bodyGo.tag = "DynamicPropDetector"; @@ -90,8 +86,7 @@ public class AddPhysics : MonoBehaviour // sectors wait 3 frames and then call OnSectorOccupantsUpdated // however we wait .1 real seconds which is longer // so we have to manually call this - if (_body._simulateInSector != null) - _body.OnSectorOccupantsUpdated(); + if (_body._simulateInSector) _body.OnSectorOccupantsUpdated(); if (SuspendUntilImpact) { @@ -101,7 +96,7 @@ public class AddPhysics : MonoBehaviour _body._transform.parent = parentBody.transform; _body._suspended = true; _body._unsuspendNextUpdate = false; - + // match velocity doesnt work so just make it not targetable _body.SetIsTargetable(false); @@ -114,12 +109,16 @@ public class AddPhysics : MonoBehaviour } } + private void OnDestroy() + { + if (_impactSensor) _impactSensor.OnImpact -= OnImpact; + Locator.GetProbe().OnAnchorProbe -= OnAnchorProbe; + } + private void OnImpact(ImpactData impact) { _body.UnsuspendImmediate(false); _body.SetIsTargetable(true); - _impactSensor.OnImpact -= OnImpact; - Locator.GetProbe().OnAnchorProbe -= OnAnchorProbe; Destroy(this); } From 8c211998f6acacb9f036b35054c277e9a51c6e40 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 11 Aug 2023 16:43:34 -0400 Subject: [PATCH 25/26] Disable bad mods --- NewHorizons/Main.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index f2d5c7e7..f77b3faf 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -634,6 +634,8 @@ namespace NewHorizons { try { + if (mod.ModHelper.Manifest.Filename.Contains("Extinction")) return; + if (_firstLoad) { MountedAddons.Add(mod); From 54b57ba33ba1bfd1bd9c3452e6fe1acb9a2c1865 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 11 Aug 2023 16:52:51 -0400 Subject: [PATCH 26/26] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 56cf858b..2fb8ac31 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.14.0", + "version": "1.14.1", "owmlVersion": "2.9.3", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],