mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix gravity/map scale + some prop stuff
This commit is contained in:
parent
ea721d2519
commit
4a912056c5
@ -11,24 +11,12 @@ namespace NewHorizons.Builder.General
|
||||
{
|
||||
public static GravityVolume Make(GameObject body, AstroObject ao, IPlanetConfig config)
|
||||
{
|
||||
var parent = AstroObjectLocator.GetAstroObject(config.Orbit.PrimaryBody);
|
||||
if (parent?.gameObject?.GetComponent<FocalPointModule>() != null)
|
||||
{
|
||||
parent = parent.GetPrimaryBody();
|
||||
}
|
||||
var a = config.Orbit.SemiMajorAxis;
|
||||
|
||||
if (parent == null)
|
||||
{
|
||||
parent = GameObject.Find("Sun_Body").GetComponent<AstroObject>();
|
||||
a = 80000;
|
||||
}
|
||||
|
||||
var exponent = config.Base.GravityFallOff.Equals("linear") ? 1f : 2f;
|
||||
var m = config.Base.SurfaceGravity * Mathf.Pow(config.Base.SurfaceSize, exponent) / 0.001f;
|
||||
var M = parent.GetGravityVolume()._gravitationalMass;
|
||||
var sphereOfInfluence = a * Mathf.Pow(m / M, 2f / (3f + exponent));
|
||||
Logger.Log($"{m}, {M}, {sphereOfInfluence}, {config.Name}");
|
||||
var GM = config.Base.SurfaceGravity * Mathf.Pow(config.Base.SurfaceSize, exponent);
|
||||
|
||||
// Gravity limit will be when the acceleration it would cause is less than 0.1 m/s^2
|
||||
var gravityRadius = GM / 0.1f;
|
||||
if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius);
|
||||
|
||||
GameObject gravityGO = new GameObject("GravityWell");
|
||||
gravityGO.transform.parent = body.transform;
|
||||
@ -38,7 +26,7 @@ namespace NewHorizons.Builder.General
|
||||
|
||||
SphereCollider SC = gravityGO.AddComponent<SphereCollider>();
|
||||
SC.isTrigger = true;
|
||||
SC.radius = sphereOfInfluence;
|
||||
SC.radius = gravityRadius;
|
||||
|
||||
OWCollider OWC = gravityGO.AddComponent<OWCollider>();
|
||||
OWC.SetLODActivationMask(DynamicOccupant.Player);
|
||||
@ -48,7 +36,7 @@ namespace NewHorizons.Builder.General
|
||||
GravityVolume GV = gravityGO.AddComponent<GravityVolume>();
|
||||
GV.SetValue("_cutoffAcceleration", 0.1f);
|
||||
GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(config.Base.GravityFallOff).GetValue(GV));
|
||||
GV.SetValue("_alignmentRadius", 1.5f * config.Base.SurfaceSize);
|
||||
GV.SetValue("_alignmentRadius", config.Base.SurfaceGravity != 0 ? 1.5f * config.Base.SurfaceSize : 0f);
|
||||
GV.SetValue("_upperSurfaceRadius", config.Base.SurfaceSize);
|
||||
GV.SetValue("_lowerSurfaceRadius", 0);
|
||||
GV.SetValue("_layer", 3);
|
||||
|
||||
@ -8,24 +8,40 @@ using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
using System.Reflection;
|
||||
using NewHorizons.Utility;
|
||||
|
||||
namespace NewHorizons.Builder.Props
|
||||
{
|
||||
public static class PropBuilder
|
||||
{
|
||||
public static GameObject Make(GameObject body, string propToClone, Vector3 position, Sector sector)
|
||||
public static void Make(GameObject go, Sector sector, IPlanetConfig config)
|
||||
{
|
||||
var prefab = GameObject.Find(propToClone);
|
||||
return Make(body, prefab, position, sector);
|
||||
if (config.Props.Scatter != null) PropBuilder.Scatter(go, config.Props.Scatter, config.Base.SurfaceSize, sector);
|
||||
if(config.Props.Details != null)
|
||||
{
|
||||
foreach(var detail in config.Props.Details)
|
||||
{
|
||||
MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GameObject Make(GameObject body, GameObject prefab, Vector3 position, Sector sector)
|
||||
public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale)
|
||||
{
|
||||
var prefab = GameObject.Find(propToClone);
|
||||
return MakeDetail(go, sector, prefab, position, rotation, scale);
|
||||
}
|
||||
|
||||
public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal = false)
|
||||
{
|
||||
if (prefab == null) return null;
|
||||
|
||||
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
|
||||
prop.transform.localPosition = position;
|
||||
prop.transform.rotation = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), position.normalized);
|
||||
prop.transform.localPosition = position == null ? prefab.transform.localPosition : (Vector3)position;
|
||||
Quaternion rot = rotation == null ? prefab.transform.localRotation : Quaternion.Euler((Vector3)rotation);
|
||||
if (alignWithNormal) rot = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), ((Vector3)position).normalized);
|
||||
prop.transform.rotation = rot;
|
||||
prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale;
|
||||
prop.SetActive(false);
|
||||
|
||||
List<string> assetBundles = new List<string>();
|
||||
@ -69,7 +85,7 @@ namespace NewHorizons.Builder.Props
|
||||
return prop;
|
||||
}
|
||||
|
||||
public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector)
|
||||
private static void Scatter(GameObject go, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector)
|
||||
{
|
||||
var area = 4f * Mathf.PI * radius * radius;
|
||||
var points = FibonacciSphere((int)area);
|
||||
@ -81,7 +97,7 @@ namespace NewHorizons.Builder.Props
|
||||
{
|
||||
var randomInd = (int)Random.Range(0, points.Count);
|
||||
var point = points[randomInd];
|
||||
var prop = Make(body, prefab, point.normalized * radius, sector);
|
||||
var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f);
|
||||
if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
|
||||
if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation);
|
||||
points.RemoveAt(randomInd);
|
||||
|
||||
9
NewHorizons/External/PropModule.cs
vendored
9
NewHorizons/External/PropModule.cs
vendored
@ -10,6 +10,7 @@ namespace NewHorizons.External
|
||||
public class PropModule : Module
|
||||
{
|
||||
public ScatterInfo[] Scatter;
|
||||
public DetailInfo[] Details;
|
||||
public MVector3[] Rafts;
|
||||
|
||||
public class ScatterInfo
|
||||
@ -19,5 +20,13 @@ namespace NewHorizons.External
|
||||
public MVector3 offset;
|
||||
public MVector3 rotation;
|
||||
}
|
||||
|
||||
public class DetailInfo
|
||||
{
|
||||
public string path;
|
||||
public MVector3 position;
|
||||
public MVector3 rotation;
|
||||
public float scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,6 +159,13 @@ namespace NewHorizons
|
||||
|
||||
// I don't know what these do but they look really weird from a distance
|
||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
|
||||
|
||||
var map = GameObject.FindObjectOfType<MapController>();
|
||||
if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f;
|
||||
foreach(var cam in GameObject.FindObjectsOfType<OWCamera>())
|
||||
{
|
||||
cam.farClipPlane = FurthestOrbit * 3f;
|
||||
}
|
||||
}
|
||||
|
||||
private bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||
@ -392,7 +399,7 @@ namespace NewHorizons
|
||||
|
||||
if (body.Config.Props != null)
|
||||
{
|
||||
if (body.Config.Props.Scatter != null) PropBuilder.Scatter(go, body.Config.Props.Scatter, body.Config.Base.SurfaceSize, sector);
|
||||
PropBuilder.Make(go, sector, body.Config);
|
||||
/*
|
||||
if (body.Config.Props.Rafts != null)
|
||||
{
|
||||
|
||||
@ -58,7 +58,7 @@ namespace NewHorizons.Utility
|
||||
|
||||
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
|
||||
{
|
||||
____maxPanDistance *= 4f;
|
||||
____maxPanDistance = Main.FurthestOrbit * 1.5f;
|
||||
____maxZoomDistance *= 6f;
|
||||
____minPitchAngle = -90f;
|
||||
____zoomSpeed *= 4f;
|
||||
@ -66,7 +66,7 @@ namespace NewHorizons.Utility
|
||||
|
||||
public static void OnOWCameraAwake(OWCamera __instance)
|
||||
{
|
||||
__instance.farClipPlane *= 4f;
|
||||
__instance.farClipPlane = Main.FurthestOrbit * 3f;
|
||||
}
|
||||
|
||||
public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user