Improved gravitational sphere of influence calculations

This commit is contained in:
Nick J. Connors 2022-01-15 01:06:23 -05:00
parent 784d654d3c
commit 0e51c14b74
5 changed files with 32 additions and 4 deletions

View File

@ -49,6 +49,14 @@ namespace NewHorizons.Builder.General
astroObject.SetValue("_customName", config.Name); astroObject.SetValue("_customName", config.Name);
astroObject.SetValue("_primaryBody", primaryBody); astroObject.SetValue("_primaryBody", primaryBody);
// Expand gravitational sphere of influence of the primary to encompass this body if needed
if(primaryBody != null && !config.Orbit.IsStatic)
{
var primarySphereOfInfluence = primaryBody.GetGravityVolume().gameObject.GetComponent<SphereCollider>();
if (primarySphereOfInfluence.radius < config.Orbit.SemiMajorAxis)
primarySphereOfInfluence.radius = config.Orbit.SemiMajorAxis * 1.5f;
}
if (config.Orbit.IsTidallyLocked) if (config.Orbit.IsTidallyLocked)
{ {
var alignment = body.AddComponent<AlignWithTargetBody>(); var alignment = body.AddComponent<AlignWithTargetBody>();

View File

@ -20,7 +20,7 @@ namespace NewHorizons.Builder.General
if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius); if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius);
// To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star or black hole (this is what giants deep has) // To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star or black hole (this is what giants deep has)
if (config.Star != null || config.Singularity != null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.SurfaceSize); if (config.Star == null && config.Singularity == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.SurfaceSize);
else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.SurfaceSize); else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.SurfaceSize);
if (config.Base.SphereOfInfluence != 0f) gravityRadius = config.Base.SphereOfInfluence; if (config.Base.SphereOfInfluence != 0f) gravityRadius = config.Base.SphereOfInfluence;

View File

@ -100,6 +100,7 @@ namespace NewHorizons.Builder.Props
component.SetSector(sector); component.SetSector(sector);
} }
foreach (var component in prop.GetComponentsInChildren<Component>()) foreach (var component in prop.GetComponentsInChildren<Component>())
{ {
// TODO: Make this work or smthng // TODO: Make this work or smthng
@ -109,6 +110,7 @@ namespace NewHorizons.Builder.Props
var enabledField = component.GetType().GetField("enabled"); var enabledField = component.GetType().GetField("enabled");
if(enabledField != null && enabledField.FieldType == typeof(bool)) enabledField.SetValue(component, true); if(enabledField != null && enabledField.FieldType == typeof(bool)) enabledField.SetValue(component, true);
} }
prop.transform.position = position == null ? go.transform.position : go.transform.TransformPoint((Vector3)position); prop.transform.position = position == null ? go.transform.position : go.transform.TransformPoint((Vector3)position);

View File

@ -202,6 +202,19 @@ namespace NewHorizons
Logger.Log($"Is the player warping in? {IsWarping}"); Logger.Log($"Is the player warping in? {IsWarping}");
if (IsWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 1); if (IsWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 1);
IsWarping = false; IsWarping = false;
// Fix some camera stuff
/*
foreach(var owc in GameObject.FindObjectsOfType<OWCamera>())
{
var far = Main.FurthestOrbit * 10f;
if (owc.farClipPlane < far)
{
owc.farClipPlane = far;
owc.mainCamera.farClipPlane = far;
}
}
*/
} }
#region TitleScreen #region TitleScreen
@ -515,7 +528,7 @@ namespace NewHorizons
LavaBuilder.Make(go, sector, rb, lava); LavaBuilder.Make(go, sector, rb, lava);
} }
if (body.Config.Lava != null) if (body.Config.Lava != null)
LavaBuilder.Make(go, sector, rb, body.Config.Lava); LavaBuilder.Make(go, sector, rb, body.Config.Lava);
// Backwards compatability // Backwards compatability

View File

@ -80,16 +80,21 @@ namespace NewHorizons.Utility
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed) public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
{ {
Logger.Log($"Other far? {Main.FurthestOrbit}");
____maxPanDistance = Main.FurthestOrbit * 1.5f; ____maxPanDistance = Main.FurthestOrbit * 1.5f;
____maxZoomDistance *= 6f; ____maxZoomDistance *= 6f;
____minPitchAngle = -90f; ____minPitchAngle = -90f;
____zoomSpeed *= 4f; ____zoomSpeed *= 4f;
__instance._mapCamera.farClipPlane = Main.FurthestOrbit * 3f; __instance._mapCamera.farClipPlane = Main.FurthestOrbit * 10f;
} }
public static void OnOWCameraAwake(OWCamera __instance) public static void OnOWCameraAwake(OWCamera __instance)
{ {
__instance.farClipPlane *= 4f; /*
var far = Main.FurthestOrbit * 10f;
__instance.farClipPlane = far;
__instance.mainCamera.farClipPlane = far;
*/
} }
public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance) public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance)