Fix funnel anchor

Fixes #62
This commit is contained in:
Nick 2022-03-21 22:34:58 -04:00
parent 5b5698c85e
commit 60c3751130
2 changed files with 13 additions and 20 deletions

View File

@ -33,7 +33,6 @@ namespace NewHorizons.Builder.Body
funnelGO.transform.parent = go.transform; funnelGO.transform.parent = go.transform;
var owrb = funnelGO.AddComponent<OWRigidbody>(); var owrb = funnelGO.AddComponent<OWRigidbody>();
var alignment = funnelGO.AddComponent<AlignWithTargetBody>();
var matchMotion = funnelGO.AddComponent<MatchInitialMotion>(); var matchMotion = funnelGO.AddComponent<MatchInitialMotion>();
matchMotion.SetBodyToMatch(rigidbody); matchMotion.SetBodyToMatch(rigidbody);
@ -51,9 +50,9 @@ namespace NewHorizons.Builder.Body
var scaleRoot = new GameObject("ScaleRoot"); var scaleRoot = new GameObject("ScaleRoot");
scaleRoot.transform.parent = funnelGO.transform; scaleRoot.transform.parent = funnelGO.transform;
scaleRoot.transform.rotation = Quaternion.Euler(90, 0, 0); scaleRoot.transform.rotation = Quaternion.identity;
scaleRoot.transform.localPosition = new Vector3(0, 30, 0); scaleRoot.transform.localPosition = Vector3.zero;
scaleRoot.transform.localScale = new Vector3(1, 1, 1.075f); scaleRoot.transform.localScale = new Vector3(1, 1, 1);
var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform);
proxyGO.name = "Proxy_Funnel"; proxyGO.name = "Proxy_Funnel";
@ -171,10 +170,10 @@ namespace NewHorizons.Builder.Body
funnelSizeController.anchor = go.transform; funnelSizeController.anchor = go.transform;
// Finish up next tick // Finish up next tick
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, alignment, funnelSizeController, module)); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, funnelSizeController, module));
} }
private static void PostMake(GameObject funnelGO, AlignWithTargetBody alignment, FunnelController funnelSizeController, FunnelModule module) private static void PostMake(GameObject funnelGO, FunnelController funnelSizeController, FunnelModule module)
{ {
var targetAO = AstroObjectLocator.GetAstroObject(module.Target); var targetAO = AstroObjectLocator.GetAstroObject(module.Target);
var target = targetAO?.GetAttachedOWRigidbody(); var target = targetAO?.GetAttachedOWRigidbody();
@ -185,14 +184,9 @@ namespace NewHorizons.Builder.Body
return; return;
} }
alignment.SetTargetBody(target);
funnelSizeController.target = target.gameObject.transform; funnelSizeController.target = target.gameObject.transform;
funnelGO.SetActive(true); funnelGO.SetActive(true);
// This has to happen last idk
alignment.SetUsePhysicsToRotate(true);
} }
private static void AddDestructionVolumes(GameObject go, DeathType deathType) private static void AddDestructionVolumes(GameObject go, DeathType deathType)

View File

@ -13,19 +13,18 @@ namespace NewHorizons.Components
public Transform target; public Transform target;
public Transform anchor; public Transform anchor;
private void FixedUpdate() private void Update()
{ {
float num = scaleCurve == null ? 1f : scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed());
// Temporary solution that i will never get rid of // Temporary solution that i will never get rid of
transform.position = anchor.position; transform.position = anchor.position;
var dist = (transform.position - target.position).magnitude; float num = scaleCurve == null ? 1f : scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed());
transform.localScale = new Vector3(num, dist/500f, num);
} var dist = (transform.position - target.position).magnitude;
transform.localScale = new Vector3(num, num, dist / 500f);
transform.LookAt(target);
private void Update()
{
// The target or anchor could have been destroyed by a star // The target or anchor could have been destroyed by a star
if (!target.gameObject.activeInHierarchy || !anchor.gameObject.activeInHierarchy) if (!target.gameObject.activeInHierarchy || !anchor.gameObject.activeInHierarchy)
{ {