mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Try and fail to make the tails move right
This commit is contained in:
parent
52e1971568
commit
d81dde6ea0
@ -10,14 +10,53 @@ namespace NewHorizons.Builder.Body
|
|||||||
{
|
{
|
||||||
public static class CometTailBuilder
|
public static class CometTailBuilder
|
||||||
{
|
{
|
||||||
private static GameObject _tailPrefab;
|
private static GameObject _dustPrefab;
|
||||||
|
private static GameObject _gasPrefab;
|
||||||
|
|
||||||
internal static void InitPrefab()
|
internal static void InitPrefab()
|
||||||
{
|
{
|
||||||
if (_tailPrefab == null)
|
if (_dustPrefab == null)
|
||||||
{
|
{
|
||||||
_tailPrefab = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes").InstantiateInactive().Rename("Prefab_CO_Tail").DontDestroyOnLoad();
|
_dustPrefab = new GameObject("Prefab_CO_Dust").DontDestroyOnLoad();
|
||||||
}
|
|
||||||
|
var dust1 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_DustTail").Instantiate();
|
||||||
|
dust1.transform.parent = _dustPrefab.transform;
|
||||||
|
dust1.transform.localPosition = Vector3.zero;
|
||||||
|
dust1.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
var dust2 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_DustTail (1)").Instantiate();
|
||||||
|
dust2.transform.parent = _dustPrefab.transform;
|
||||||
|
dust2.transform.localPosition = Vector3.zero;
|
||||||
|
dust2.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
var dust3 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_DustTail (2)").Instantiate();
|
||||||
|
dust3.transform.parent = _dustPrefab.transform;
|
||||||
|
dust3.transform.localPosition = Vector3.zero;
|
||||||
|
dust3.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
_dustPrefab.SetActive(false);
|
||||||
|
}
|
||||||
|
if (_gasPrefab == null)
|
||||||
|
{
|
||||||
|
_gasPrefab = new GameObject("Prefab_CO_Gas").DontDestroyOnLoad();
|
||||||
|
|
||||||
|
var gas1 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_GasTail").Instantiate();
|
||||||
|
gas1.transform.parent = _gasPrefab.transform;
|
||||||
|
gas1.transform.localPosition = Vector3.zero;
|
||||||
|
gas1.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
var gas2 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_GasTail (1)").Instantiate();
|
||||||
|
gas2.transform.parent = _gasPrefab.transform;
|
||||||
|
gas2.transform.localPosition = Vector3.zero;
|
||||||
|
gas2.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
var gas3 = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes/Effects_CO_GasTail (2)").Instantiate();
|
||||||
|
gas3.transform.parent = _gasPrefab.transform;
|
||||||
|
gas3.transform.localPosition = Vector3.zero;
|
||||||
|
gas3.transform.localRotation = Quaternion.Euler(0, 270, 0);
|
||||||
|
|
||||||
|
_gasPrefab.SetActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config)
|
public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config)
|
||||||
@ -27,11 +66,6 @@ namespace NewHorizons.Builder.Body
|
|||||||
rootObj.transform.parent = sector?.transform ?? planetGO.transform;
|
rootObj.transform.parent = sector?.transform ?? planetGO.transform;
|
||||||
rootObj.transform.localPosition = Vector3.zero;
|
rootObj.transform.localPosition = Vector3.zero;
|
||||||
|
|
||||||
var cometTail = GameObject.Instantiate(_tailPrefab, rootObj.transform).Rename("CometTail");
|
|
||||||
cometTail.transform.localPosition = Vector3.zero;
|
|
||||||
cometTail.transform.localRotation = Quaternion.Euler(90, 90, 0);
|
|
||||||
cometTail.SetActive(true);
|
|
||||||
|
|
||||||
var controller = rootObj.AddComponent<CometTailController>();
|
var controller = rootObj.AddComponent<CometTailController>();
|
||||||
|
|
||||||
controller.size = (cometTailModule.innerRadius ?? config.Base.surfaceSize) / 110;
|
controller.size = (cometTailModule.innerRadius ?? config.Base.surfaceSize) / 110;
|
||||||
@ -47,6 +81,18 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
controller.SetScaleCurve(cometTailModule.curve);
|
controller.SetScaleCurve(cometTailModule.curve);
|
||||||
|
|
||||||
|
var dustTail = GameObject.Instantiate(_dustPrefab, rootObj.transform).Rename("DustTail");
|
||||||
|
dustTail.transform.localPosition = Vector3.zero;
|
||||||
|
dustTail.transform.localRotation = Quaternion.Euler(90, 90, 0);
|
||||||
|
dustTail.SetActive(true);
|
||||||
|
controller.dustTail = dustTail;
|
||||||
|
|
||||||
|
var gasTail = GameObject.Instantiate(_gasPrefab, rootObj.transform).Rename("GasTail");
|
||||||
|
gasTail.transform.localPosition = Vector3.zero;
|
||||||
|
gasTail.transform.localRotation = Quaternion.Euler(90, 90, 0);
|
||||||
|
gasTail.SetActive(true);
|
||||||
|
controller.gasTail = gasTail;
|
||||||
|
|
||||||
rootObj.SetActive(true);
|
rootObj.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
using NewHorizons.Utility;
|
||||||
|
using NewHorizons.Utility.OWML;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NewHorizons.Components.SizeControllers
|
namespace NewHorizons.Components.SizeControllers
|
||||||
@ -10,9 +12,24 @@ namespace NewHorizons.Components.SizeControllers
|
|||||||
private bool _hasRotationOverride;
|
private bool _hasRotationOverride;
|
||||||
private bool _hasPrimaryBody;
|
private bool _hasPrimaryBody;
|
||||||
|
|
||||||
|
public GameObject gasTail;
|
||||||
|
public GameObject dustTail;
|
||||||
|
|
||||||
|
private Vector3 _gasTarget;
|
||||||
|
private Vector3 _dustTarget;
|
||||||
|
|
||||||
|
private float _angularVelocity = 1f;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
_body = transform.GetAttachedOWRigidbody();
|
_body = transform.GetAttachedOWRigidbody();
|
||||||
|
|
||||||
|
if (!_hasRotationOverride && _hasPrimaryBody)
|
||||||
|
{
|
||||||
|
UpdateTargetPositions();
|
||||||
|
dustTail?.transform?.LookAt(_dustTarget);
|
||||||
|
gasTail?.transform?.LookAt(_gasTarget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void FixedUpdate()
|
public override void FixedUpdate()
|
||||||
@ -21,10 +38,24 @@ namespace NewHorizons.Components.SizeControllers
|
|||||||
|
|
||||||
if (!_hasRotationOverride && _hasPrimaryBody)
|
if (!_hasRotationOverride && _hasPrimaryBody)
|
||||||
{
|
{
|
||||||
transform.LookAt(_primaryBody, _body.GetVelocity().normalized);
|
UpdateTargetPositions();
|
||||||
|
|
||||||
|
dustTail?.SmoothLookAt(_dustTarget, Time.deltaTime, _angularVelocity);
|
||||||
|
gasTail?.SmoothLookAt(_gasTarget, Time.deltaTime, _angularVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateTargetPositions()
|
||||||
|
{
|
||||||
|
var toPrimary = (_body.transform.position - _primaryBody.transform.position).normalized;
|
||||||
|
var velocityDirection = -_body.GetVelocity(); // Accept that this is flipped ok
|
||||||
|
|
||||||
|
var tangentVel = Vector3.ProjectOnPlane(velocityDirection, toPrimary) / velocityDirection.magnitude;
|
||||||
|
|
||||||
|
_gasTarget = toPrimary;
|
||||||
|
_dustTarget = (toPrimary + tangentVel).normalized;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetRotationOverride(Vector3 eulerAngles)
|
public void SetRotationOverride(Vector3 eulerAngles)
|
||||||
{
|
{
|
||||||
_hasRotationOverride = true;
|
_hasRotationOverride = true;
|
||||||
|
|||||||
@ -71,6 +71,8 @@ namespace NewHorizons.Components.SizeControllers
|
|||||||
|
|
||||||
public void SetScaleCurve(TimeValuePair[] curve)
|
public void SetScaleCurve(TimeValuePair[] curve)
|
||||||
{
|
{
|
||||||
|
if (curve == null) return;
|
||||||
|
|
||||||
scaleCurve = new AnimationCurve();
|
scaleCurve = new AnimationCurve();
|
||||||
foreach (var pair in curve)
|
foreach (var pair in curve)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -255,5 +255,15 @@ namespace NewHorizons.Utility
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static FluidVolume.Type ConvertToOW(this NHFluidType fluidType, FluidVolume.Type @default = FluidVolume.Type.NONE) => EnumUtils.Parse(fluidType.ToString().ToUpper(), @default);
|
public static FluidVolume.Type ConvertToOW(this NHFluidType fluidType, FluidVolume.Type @default = FluidVolume.Type.NONE) => EnumUtils.Parse(fluidType.ToString().ToUpper(), @default);
|
||||||
|
|
||||||
|
public static void SmoothLookAt(this GameObject go, Vector3 direction, float dt, float angularVelocity)
|
||||||
|
{
|
||||||
|
var start = go.transform.rotation;
|
||||||
|
var end = Quaternion.FromToRotation(Vector3.forward, direction);
|
||||||
|
|
||||||
|
var angle = Quaternion.Angle(start, end);
|
||||||
|
|
||||||
|
go.transform.rotation = Quaternion.Slerp(start, end, angularVelocity / angle * dt * dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,16 +13,16 @@ namespace NewHorizons.Utility.OWML
|
|||||||
_logLevel = newLevel;
|
_logLevel = newLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Log(string text, LogType type)
|
private static void Log(object text, LogType type)
|
||||||
{
|
{
|
||||||
if (type < _logLevel) return;
|
if (type < _logLevel) return;
|
||||||
Main.Instance.ModHelper.Console.WriteLine($"{Enum.GetName(typeof(LogType), type)} : {text}", LogTypeToMessageType(type));
|
Main.Instance.ModHelper.Console.WriteLine($"{Enum.GetName(typeof(LogType), type)} : {text}", LogTypeToMessageType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogVerbose(string text) => Log(text, LogType.Verbose);
|
public static void LogVerbose(object text) => Log(text, LogType.Verbose);
|
||||||
public static void Log(string text) => Log(text, LogType.Log);
|
public static void Log(object text) => Log(text, LogType.Log);
|
||||||
public static void LogWarning(string text) => Log(text, LogType.Warning);
|
public static void LogWarning(object text) => Log(text, LogType.Warning);
|
||||||
public static void LogError(string text) => Log(text, LogType.Error);
|
public static void LogError(object text) => Log(text, LogType.Error);
|
||||||
|
|
||||||
public enum LogType
|
public enum LogType
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user