mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Lock using camera, don't appear in front of you
This commit is contained in:
parent
50f898e0c7
commit
5894f1df0c
@ -8,15 +8,15 @@ using Logger = NewHorizons.Utility.Logger;
|
|||||||
|
|
||||||
namespace NewHorizons.Components.Orbital
|
namespace NewHorizons.Components.Orbital
|
||||||
{
|
{
|
||||||
public class OrbitalParameters
|
public class OrbitalParameters : IOrbitalParameters
|
||||||
{
|
{
|
||||||
public float Inclination { get; private set; }
|
public float Inclination { get; set; }
|
||||||
public float SemiMajorAxis { get; private set; }
|
public float SemiMajorAxis { get; set; }
|
||||||
public float LongitudeOfAscendingNode { get; private set; }
|
public float LongitudeOfAscendingNode { get; set; }
|
||||||
public float Eccentricity { get; private set; }
|
public float Eccentricity { get; set; }
|
||||||
public float ArgumentOfPeriapsis { get; private set; }
|
public float ArgumentOfPeriapsis { get; set; }
|
||||||
public float TrueAnomaly { get; private set; }
|
public float TrueAnomaly { get; set; }
|
||||||
public float Period { get; private set; }
|
public float Period { get; set; }
|
||||||
|
|
||||||
public Vector3 InitialPosition { get; private set; }
|
public Vector3 InitialPosition { get; private set; }
|
||||||
public Vector3 InitialVelocity { get; private set; }
|
public Vector3 InitialVelocity { get; private set; }
|
||||||
@ -112,5 +112,10 @@ namespace NewHorizons.Components.Orbital
|
|||||||
|
|
||||||
return R1 * R2 * vector;
|
return R1 * R2 * vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OrbitalParameters GetOrbitalParameters(Gravity primaryGravity, Gravity secondaryGravity)
|
||||||
|
{
|
||||||
|
return FromTrueAnomaly(primaryGravity, secondaryGravity, Eccentricity, SemiMajorAxis, Inclination, ArgumentOfPeriapsis, LongitudeOfAscendingNode, TrueAnomaly);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,13 +36,15 @@ namespace NewHorizons.Components
|
|||||||
_rb = GetComponent<OWRigidbody>();
|
_rb = GetComponent<OWRigidbody>();
|
||||||
|
|
||||||
GlobalMessenger.AddListener("PlayerBlink", new Callback(OnPlayerBlink));
|
GlobalMessenger.AddListener("PlayerBlink", new Callback(OnPlayerBlink));
|
||||||
|
|
||||||
|
_maxSnapshotLockRange = 300000f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
|
|
||||||
foreach(var state in states)
|
foreach (var state in states)
|
||||||
{
|
{
|
||||||
state.sector?.gameObject?.SetActive(false);
|
state.sector?.gameObject?.SetActive(false);
|
||||||
}
|
}
|
||||||
@ -52,23 +54,68 @@ namespace NewHorizons.Components
|
|||||||
|
|
||||||
public override bool ChangeQuantumState(bool skipInstantVisibilityCheck)
|
public override bool ChangeQuantumState(bool skipInstantVisibilityCheck)
|
||||||
{
|
{
|
||||||
Logger.Log($"Changing quantum state");
|
Logger.Log($"Trying to change quantum state");
|
||||||
|
|
||||||
if (states.Count <= 1) return false;
|
if (states.Count <= 1) return false;
|
||||||
|
|
||||||
var newIndex = _currentIndex;
|
// Don't move if we have a picture or if we're on it
|
||||||
while(newIndex == _currentIndex)
|
if (IsLockedByProbeSnapshot() || IsPlayerEntangled()) return false;
|
||||||
|
|
||||||
|
var canChange = false;
|
||||||
|
|
||||||
|
var oldState = states[_currentIndex];
|
||||||
|
|
||||||
|
// This will all get set in the for loop
|
||||||
|
State newState = oldState;
|
||||||
|
int newIndex = _currentIndex;
|
||||||
|
AstroObject primaryBody = null;
|
||||||
|
OrbitalParameters orbitalParams = null;
|
||||||
|
|
||||||
|
// The QM tries to switch 10 times so we'll do that too
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
newIndex = _currentIndex;
|
||||||
|
while (newIndex == _currentIndex)
|
||||||
{
|
{
|
||||||
newIndex = Random.Range(0, states.Count);
|
newIndex = Random.Range(0, states.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldState = states[_currentIndex];
|
newState = states[newIndex];
|
||||||
var newState = states[newIndex];
|
|
||||||
|
|
||||||
|
// Figure out what the new orbit will be if we switch
|
||||||
|
var newOrbit = newState.orbit ?? groundState.orbit;
|
||||||
|
newOrbit.TrueAnomaly = Random.Range(0f, 360f);
|
||||||
|
|
||||||
|
primaryBody = AstroObjectLocator.GetAstroObject(newOrbit.PrimaryBody);
|
||||||
|
var primaryGravity = new Gravity(primaryBody.GetGravityVolume());
|
||||||
|
var secondaryGravity = new Gravity(_astroObject.GetGravityVolume());
|
||||||
|
orbitalParams = newOrbit.GetOrbitalParameters(primaryGravity, secondaryGravity);
|
||||||
|
|
||||||
|
var pos = primaryBody.transform.position + orbitalParams.InitialPosition;
|
||||||
|
|
||||||
|
// See if we can switch, so we move the visibility tracker to the new position
|
||||||
|
_visibilityTrackers[0].transform.position = pos;
|
||||||
|
|
||||||
|
// Only if not seen
|
||||||
|
if (!CheckVisibilityInstantly())
|
||||||
|
{
|
||||||
|
canChange = true;
|
||||||
|
|
||||||
|
// Since we were able to change states we break
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canChange)
|
||||||
|
{
|
||||||
if (newState.sector != null && newState.sector != oldState.sector) SetNewSector(oldState, newState);
|
if (newState.sector != null && newState.sector != oldState.sector) SetNewSector(oldState, newState);
|
||||||
if (newState.orbit != null && newState.orbit != oldState.orbit) SetNewOrbit(newState);
|
if (newState.orbit != null && newState.orbit != oldState.orbit) SetNewOrbit(primaryBody, orbitalParams);
|
||||||
|
|
||||||
_currentIndex = newIndex;
|
_currentIndex = newIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Be completely sure we move the visibility tracker back to our planet
|
||||||
|
_visibilityTrackers[0].transform.localPosition = Vector3.zero;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -79,23 +126,22 @@ namespace NewHorizons.Components
|
|||||||
newState.sector.gameObject.SetActive(true);
|
newState.sector.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetNewOrbit(State state)
|
private void SetNewOrbit(AstroObject primaryBody, OrbitalParameters orbitalParameters)
|
||||||
{
|
{
|
||||||
var currentOrbit = state.orbit;
|
|
||||||
|
|
||||||
var primaryBody = AstroObjectLocator.GetAstroObject(currentOrbit.PrimaryBody);
|
|
||||||
|
|
||||||
_astroObject._primaryBody = primaryBody;
|
_astroObject._primaryBody = primaryBody;
|
||||||
DetectorBuilder.SetDetector(primaryBody, _astroObject, _detector);
|
DetectorBuilder.SetDetector(primaryBody, _astroObject, _detector);
|
||||||
if (_alignment != null) _alignment.SetTargetBody(primaryBody.GetComponent<OWRigidbody>());
|
if (_alignment != null) _alignment.SetTargetBody(primaryBody.GetComponent<OWRigidbody>());
|
||||||
|
|
||||||
currentOrbit.TrueAnomaly = Random.Range(0, 360);
|
PlanetCreationHandler.UpdatePosition(gameObject, orbitalParameters, primaryBody, _astroObject);
|
||||||
PlanetCreationHandler.UpdatePosition(gameObject, currentOrbit, primaryBody, _astroObject);
|
|
||||||
|
|
||||||
var primaryGravity = new Gravity(primaryBody.GetGravityVolume());
|
if (!Physics.autoSyncTransforms)
|
||||||
var secondaryGravity = new Gravity(_astroObject.GetGravityVolume());
|
{
|
||||||
|
Physics.SyncTransforms();
|
||||||
|
}
|
||||||
|
|
||||||
_rb.SetVelocity(currentOrbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialVelocity);
|
_rb.SetVelocity(orbitalParameters.InitialVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlayerBlink()
|
private void OnPlayerBlink()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user