More attempts at funnels

This commit is contained in:
Nick J. Connors 2022-01-19 13:23:20 -05:00
parent 73de80bcc0
commit 022fc643da
3 changed files with 20 additions and 8 deletions

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Body
{
@ -19,7 +20,7 @@ namespace NewHorizons.Builder.Body
STAR
}
public static void Make(GameObject go, ConstantForceDetector detector, FunnelModule module)
public static void Make(GameObject go, ConstantForceDetector detector, InitialMotion initialMotion, FunnelModule module)
{
var funnelType = FunnelType.SAND;
if (module.Type.ToUpper().Equals("WATER")) funnelType = FunnelType.WATER;
@ -32,7 +33,12 @@ namespace NewHorizons.Builder.Body
var owrb = funnelGO.AddComponent<OWRigidbody>();
var alignment = funnelGO.AddComponent<AlignWithTargetBody>();
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => alignment.SetTargetBody(AstroObjectLocator.GetAstroObject(module.Target)?.GetAttachedOWRigidbody()));
funnelGO.AddComponent<InitialMotion>();
var im = funnelGO.AddComponent<InitialMotion>();
var velocity = initialMotion.GetInitVelocity();
im._initLinearDirection = initialMotion._initLinearDirection;
im._initLinearSpeed = initialMotion._initLinearSpeed;
funnelGO.AddComponent<SandFunnelController>();
funnelGO.AddComponent<CenterOfTheUniverseOffsetApplier>();
funnelGO.AddComponent<KinematicRigidbody>();
@ -41,11 +47,12 @@ namespace NewHorizons.Builder.Body
detectorGO.transform.parent = funnelGO.transform;
var funnelDetector = detectorGO.AddComponent<ConstantForceDetector>();
funnelDetector._inheritDetector = detector;
funnelDetector._detectableFields = new ForceVolume[0];
detectorGO.AddComponent<ForceApplier>();
var scaleRoot = new GameObject("ScaleRoot");
scaleRoot.transform.parent = go.transform;
scaleRoot.transform.parent = funnelGO.transform;
var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform);
proxyGO.name = "Proxy_Funnel";
@ -55,7 +62,7 @@ namespace NewHorizons.Builder.Body
var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform);
volumesGO.name = "Volumes_Funnel";
var sfv = volumesGO.GetComponent<SimpleFluidVolume>();
var sfv = volumesGO.GetComponentInChildren<SimpleFluidVolume>();
switch(funnelType)
{
case FunnelType.SAND:
@ -72,6 +79,8 @@ namespace NewHorizons.Builder.Body
break;
}
funnelGO.transform.position = go.transform.position;
funnelGO.SetActive(true);
}
}
}

View File

@ -33,6 +33,9 @@ namespace NewHorizons.Builder.General
owRigidBody.SetValue("_maintainOriginalCenterOfMass", true);
owRigidBody.SetValue("_rigidbody", rigidBody);
owRigidBody.SetValue("_kinematicRigidbody", kinematicRigidBody);
owRigidBody._origParent = GameObject.Find("SolarSystemRoot").transform;
owRigidBody.EnableKinematicSimulation();
owRigidBody.MakeKinematic();
ParameterizedAstroObject astroObject = body.AddComponent<ParameterizedAstroObject>();

View File

@ -497,7 +497,7 @@ namespace NewHorizons
if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao);
if (body.Config.Funnel != null)
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), body.Config.Funnel);
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), initialMotion, body.Config.Funnel);
if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao);