mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Finish tornados (missing sound)
This commit is contained in:
parent
859adc0ff4
commit
9faa08a0c8
@ -49,7 +49,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
foreach(var tornadoInfo in config.Props.Tornados)
|
foreach(var tornadoInfo in config.Props.Tornados)
|
||||||
{
|
{
|
||||||
//TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null);
|
TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.Props.Volcanoes != null)
|
if (config.Props.Volcanoes != null)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using NewHorizons.Components;
|
using NewHorizons.Components;
|
||||||
using NewHorizons.External;
|
using NewHorizons.External;
|
||||||
|
using NewHorizons.Handlers;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -8,88 +9,91 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace NewHorizons.Builder.Props
|
namespace NewHorizons.Builder.Props
|
||||||
{
|
{
|
||||||
public static class TornadoBuilder
|
public static class TornadoBuilder
|
||||||
{
|
{
|
||||||
public static string tornadoParentName = "Tornados";
|
private static GameObject upPrefab;
|
||||||
|
private static GameObject downPrefab;
|
||||||
|
|
||||||
public static void Make(GameObject go, Sector sector, PropModule.TornadoInfo info, bool hasClouds)
|
public static void Make(GameObject go, Sector sector, PropModule.TornadoInfo info, bool hasClouds)
|
||||||
{
|
{
|
||||||
// If we are given elevation choose a random position
|
if (upPrefab == null)
|
||||||
Vector3 position;
|
|
||||||
float elevation = 0f;
|
|
||||||
|
|
||||||
if (info.position != null)
|
|
||||||
{
|
{
|
||||||
position = info.position;
|
upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive();
|
||||||
|
upPrefab.name = "Tornado_Up_Prefab";
|
||||||
|
}
|
||||||
|
if(downPrefab == null)
|
||||||
|
{
|
||||||
|
downPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive();
|
||||||
|
downPrefab.name = "Tornado_Down_Prefab";
|
||||||
|
downPrefab.name = "Tornado_Down_Prefab";
|
||||||
|
}
|
||||||
|
|
||||||
|
float elevation;
|
||||||
|
Vector3 position;
|
||||||
|
if(info.position != null)
|
||||||
|
{
|
||||||
|
position = info.position ?? Random.onUnitSphere * info.elevation;
|
||||||
elevation = position.magnitude;
|
elevation = position.magnitude;
|
||||||
}
|
}
|
||||||
else if (info.elevation != 0f)
|
else if(info.elevation != 0)
|
||||||
{
|
{
|
||||||
Logger.Log("Giving tornado random pos");
|
position = Random.onUnitSphere * info.elevation;
|
||||||
position = UnityEngine.Random.insideUnitSphere * info.elevation;
|
|
||||||
elevation = info.elevation;
|
elevation = info.elevation;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogError($"Couldn't make tornado for {go.name}: No elevation or position was given");
|
Logger.LogError($"Need either a position or an elevation for tornados");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado");
|
var tornadoGO = info.downwards ? downPrefab.InstantiateInactive() : upPrefab.InstantiateInactive();
|
||||||
var downPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado");
|
tornadoGO.transform.parent = sector.transform;
|
||||||
// Default radius is 40, height is 837.0669
|
tornadoGO.transform.localPosition = position;
|
||||||
|
tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized));
|
||||||
|
|
||||||
var tornadoGO = upPrefab.InstantiateInactive();
|
var scale = info.height == 0 ? 1 : info.height / 10f;
|
||||||
tornadoGO.transform.parent = sector?.transform ?? go.transform;
|
|
||||||
tornadoGO.transform.localPosition = Vector3.zero;
|
|
||||||
var tornado = tornadoGO.GetComponent<TornadoController>();
|
|
||||||
tornado.SetSector(sector);
|
|
||||||
|
|
||||||
var height = 837.0669f;
|
tornadoGO.transform.localScale = Vector3.one * scale;
|
||||||
if (info.height != 0f) height = info.height;
|
|
||||||
|
|
||||||
var width = 40f;
|
var controller = tornadoGO.GetComponent<TornadoController>();
|
||||||
if (info.width != 0f) width = info.width;
|
controller.SetSector(sector);
|
||||||
|
|
||||||
tornado._bottomBone.localPosition = new Vector3(0, elevation, 0);
|
controller._bottomStartPos = Vector3.up * -20;
|
||||||
tornado._midBone.localPosition = new Vector3(0, elevation + height / 2f, 0);
|
controller._midStartPos = Vector3.up * 150;
|
||||||
tornado._topBone.localPosition = new Vector3(0, elevation + height, 0);
|
controller._topStartPos = Vector3.up * 300;
|
||||||
|
|
||||||
tornado._startActive = false;
|
controller._bottomBone.localPosition = controller._bottomStartPos;
|
||||||
|
controller._midBone.localPosition = controller._midStartPos;
|
||||||
|
controller._topBone.localPosition = controller._topStartPos;
|
||||||
|
|
||||||
// TODO make these settings
|
OWAssetHandler.LoadObject(tornadoGO);
|
||||||
tornado._wanderRate = 0.5f;
|
sector.OnOccupantEnterSector += (sd) => OWAssetHandler.LoadObject(tornadoGO);
|
||||||
tornado._wanderDegreesX = 45f;
|
|
||||||
tornado._wanderDegreesZ = 45f;
|
|
||||||
|
|
||||||
/*
|
tornadoGO.GetComponentInChildren<CapsuleShape>().enabled = true;
|
||||||
if (!hasClouds)
|
|
||||||
|
if(info.tint != null)
|
||||||
{
|
{
|
||||||
var fix = tornadoGO.AddComponent<TornadoFix>();
|
var colour = info.tint.ToColor();
|
||||||
fix.SetSector(sector);
|
foreach(var renderer in tornadoGO.GetComponentsInChildren<Renderer>())
|
||||||
|
|
||||||
var top = tornadoGO.transform.Find("UpTornado/Effects_GD_TornadoCyclone/Tornado_Top");
|
|
||||||
|
|
||||||
// Get rid of the bit that appears above the clouds
|
|
||||||
GameObject.Destroy(top.transform.Find("Effects_GD_TornadoCloudCap_Large")?.gameObject);
|
|
||||||
GameObject.Destroy(top.transform.Find("Effects_GD_TornadoCloudCap_Medium")?.gameObject);
|
|
||||||
GameObject.Destroy(top.transform.Find("Effects_GD_TornadoCloudCap_Small")?.gameObject);
|
|
||||||
|
|
||||||
var top_objects = new GameObject[3];
|
|
||||||
top_objects[0] = GameObject.Instantiate(top.transform.Find("Effects_GD_TornadoCloudBlend_Large").gameObject, top.transform);
|
|
||||||
top_objects[1] = GameObject.Instantiate(top.transform.Find("Effects_GD_TornadoCloudBlend_Medium").gameObject, top.transform);
|
|
||||||
top_objects[2] = GameObject.Instantiate(top.transform.Find("Effects_GD_TornadoCloudBlend_Small").gameObject, top.transform);
|
|
||||||
|
|
||||||
foreach(var obj in top_objects)
|
|
||||||
{
|
{
|
||||||
obj.transform.localPosition = new Vector3(0, -20, 0);
|
renderer.material.color = colour;
|
||||||
obj.transform.localRotation = Quaternion.Euler(180, 0, 0);
|
renderer.material.SetColor("_DetailColor", colour);
|
||||||
|
renderer.material.SetColor("_TintColor", colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
if(info.wanderRate != 0)
|
||||||
|
{
|
||||||
|
var wanderer = tornadoGO.AddComponent<NHTornadoWanderController>();
|
||||||
|
wanderer.wanderRate = info.wanderRate;
|
||||||
|
wanderer.wanderDegreesX = info.wanderDegreesX;
|
||||||
|
wanderer.wanderDegreesZ = info.wanderDegreesZ;
|
||||||
|
wanderer.sector = sector;
|
||||||
|
}
|
||||||
|
|
||||||
tornadoGO.SetActive(true);
|
tornadoGO.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|||||||
56
NewHorizons/Components/NHTornadoWanderController.cs
Normal file
56
NewHorizons/Components/NHTornadoWanderController.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
namespace NewHorizons.Components
|
||||||
|
{
|
||||||
|
public class NHTornadoWanderController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float wanderRate;
|
||||||
|
public float wanderDegreesX;
|
||||||
|
public float wanderDegreesZ;
|
||||||
|
public Sector sector;
|
||||||
|
|
||||||
|
private float noiseOffset;
|
||||||
|
private float startDegreesX;
|
||||||
|
private float startDegreesZ;
|
||||||
|
|
||||||
|
private float elevation;
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
noiseOffset = Random.value;
|
||||||
|
|
||||||
|
var x = transform.localPosition.x;
|
||||||
|
var y = transform.localPosition.y;
|
||||||
|
var z = transform.localPosition.z;
|
||||||
|
|
||||||
|
elevation = Mathf.Sqrt(x * x + y * y + z * z);
|
||||||
|
|
||||||
|
startDegreesX = Mathf.Rad2Deg * Mathf.Atan2(y, x); //theta
|
||||||
|
startDegreesZ = Mathf.Rad2Deg * Mathf.Acos(z / elevation); //phi
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
float num = Mathf.PerlinNoise(Time.time * wanderRate + noiseOffset, 0f) * 2f - 1f;
|
||||||
|
float num2 = Mathf.PerlinNoise(Time.time * wanderRate + noiseOffset, 5f) * 2f - 1f;
|
||||||
|
|
||||||
|
var newDegreesX = startDegreesX + num * wanderDegreesX;
|
||||||
|
var newDegreesZ = startDegreesZ + num2 * wanderDegreesZ;
|
||||||
|
|
||||||
|
var newX = elevation * Mathf.Sin(Mathf.Deg2Rad * newDegreesZ) * Mathf.Cos(Mathf.Deg2Rad * newDegreesX);
|
||||||
|
var newY = elevation * Mathf.Sin(Mathf.Deg2Rad * newDegreesZ) * Mathf.Sin(Mathf.Deg2Rad * newDegreesX);
|
||||||
|
var newZ = elevation * Mathf.Cos(Mathf.Deg2Rad * newDegreesZ);
|
||||||
|
|
||||||
|
var newPos = new Vector3(newX, newY, newZ);
|
||||||
|
|
||||||
|
transform.localPosition = newPos;
|
||||||
|
transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(newPos.normalized));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
NewHorizons/External/PropModule.cs
vendored
7
NewHorizons/External/PropModule.cs
vendored
@ -57,11 +57,14 @@ namespace NewHorizons.External
|
|||||||
|
|
||||||
public class TornadoInfo
|
public class TornadoInfo
|
||||||
{
|
{
|
||||||
|
public MVector3 position;
|
||||||
public float elevation;
|
public float elevation;
|
||||||
public MVector3 position = null;
|
|
||||||
public float height;
|
public float height;
|
||||||
public float width;
|
|
||||||
public MColor tint;
|
public MColor tint;
|
||||||
|
public bool downwards;
|
||||||
|
public float wanderRate;
|
||||||
|
public float wanderDegreesX = 45;
|
||||||
|
public float wanderDegreesZ = 45;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VolcanoInfo
|
public class VolcanoInfo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user