Fix primary body stuff

This commit is contained in:
Nick 2023-04-22 15:51:36 -04:00
parent 8606b8a5b6
commit 2ad9784b34
2 changed files with 16 additions and 5 deletions

View File

@ -62,6 +62,12 @@ namespace NewHorizons.Builder.Body
public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config) public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config)
{ {
if (config.Orbit.primaryBody == null)
{
NHLogger.LogError($"Comet {planetGO.name} does not orbit anything. That makes no sense");
return;
}
var rootObj = new GameObject("CometRoot"); var rootObj = new GameObject("CometRoot");
rootObj.SetActive(false); rootObj.SetActive(false);
rootObj.transform.parent = sector?.transform ?? planetGO.transform; rootObj.transform.parent = sector?.transform ?? planetGO.transform;
@ -77,7 +83,10 @@ namespace NewHorizons.Builder.Body
Delay.FireOnNextUpdate(() => Delay.FireOnNextUpdate(() =>
{ {
controller.SetPrimaryBody(AstroObjectLocator.GetAstroObject(cometTailModule.primaryBody).transform); controller.SetPrimaryBody(
AstroObjectLocator.GetAstroObject(cometTailModule.primaryBody).transform,
AstroObjectLocator.GetAstroObject(config.Orbit.primaryBody).GetAttachedOWRigidbody()
);
}); });
controller.SetScaleCurve(cometTailModule.curve); controller.SetScaleCurve(cometTailModule.curve);

View File

@ -6,7 +6,8 @@ namespace NewHorizons.Components.SizeControllers
{ {
public class CometTailController : SizeController public class CometTailController : SizeController
{ {
private Transform _primaryBody; private Transform _dustTargetBody;
private OWRigidbody _primaryBody;
private OWRigidbody _body; private OWRigidbody _body;
private bool _hasRotationOverride; private bool _hasRotationOverride;
@ -38,8 +39,8 @@ namespace NewHorizons.Components.SizeControllers
private void UpdateTargetPositions() private void UpdateTargetPositions()
{ {
var toPrimary = (_body.transform.position - _primaryBody.transform.position).normalized; var toPrimary = (_body.transform.position - _dustTargetBody.transform.position).normalized;
var velocityDirection = -_body.GetVelocity(); // Accept that this is flipped ok var velocityDirection = (_primaryBody?.GetVelocity() ?? Vector3.zero) -_body.GetVelocity(); // Accept that this is flipped ok
var tangentVel = Vector3.ProjectOnPlane(velocityDirection, toPrimary) / velocityDirection.magnitude; var tangentVel = Vector3.ProjectOnPlane(velocityDirection, toPrimary) / velocityDirection.magnitude;
@ -53,9 +54,10 @@ namespace NewHorizons.Components.SizeControllers
transform.localRotation = Quaternion.Euler(eulerAngles); transform.localRotation = Quaternion.Euler(eulerAngles);
} }
public void SetPrimaryBody(Transform primaryBody) public void SetPrimaryBody(Transform dustTarget, OWRigidbody primaryBody)
{ {
_hasPrimaryBody = true; _hasPrimaryBody = true;
_dustTargetBody = dustTarget;
_primaryBody = primaryBody; _primaryBody = primaryBody;
} }
} }