From 3d61e5248571bbd798c5d2ed3535abd25cab98c3 Mon Sep 17 00:00:00 2001 From: Koruzarius <113130738+Koruzarius@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:15:24 -0400 Subject: [PATCH] Bug fix for close planets and moons There was an issue with the comparison to find which planet to spawn in reference to where a small and large body close together caused issues. Changed it to use the distance to the *surface* to compare, instead of the core. --- .../Entities/PlanetManager.cs | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/Data/Scripts/ModularEncountersSystems/Entities/PlanetManager.cs b/Data/Scripts/ModularEncountersSystems/Entities/PlanetManager.cs index b755f4a5..34cc3406 100644 --- a/Data/Scripts/ModularEncountersSystems/Entities/PlanetManager.cs +++ b/Data/Scripts/ModularEncountersSystems/Entities/PlanetManager.cs @@ -31,11 +31,10 @@ public static float AirDensityAtPosition(Vector3D pos) { return 0; } - + public static PlanetEntity GetNearestPlanet(Vector3D coords) { PlanetEntity planet = null; - bool inGravity = false; double distance = -1; foreach (var planetEnt in Planets) { @@ -44,29 +43,15 @@ public static PlanetEntity GetNearestPlanet(Vector3D coords) { continue; if (planetEnt.IsPositionInGravity(coords)) { + var thisDist = Math.Abs(Vector3D.Distance(planetEnt.Center(), coords)-planetEnt.Planet.AverageRadius); - planet = planetEnt; - inGravity = true; - - } else if (inGravity) { - - continue; - - } - - var thisDist = Vector3D.Distance(planetEnt.Center(), coords); - - if (distance == -1 || thisDist < distance) { - - planet = planetEnt; - distance = thisDist; - - } - + if (distance == -1 || thisDist < distance) { + planet = planetEnt; + distance = thisDist; + } + } } - return planet; - } public static PlanetEntity GetPlanetWithName(string generatorName) {