Make tidal locking affecting spawn more consistent

This commit is contained in:
Nick 2023-07-18 11:07:19 -04:00
parent 5202326fce
commit f8cc0e4b64
2 changed files with 9 additions and 5 deletions

View File

@ -46,13 +46,17 @@ namespace NewHorizons.Builder.General
var alignment = body.AddComponent<AlignWithTargetBody>(); var alignment = body.AddComponent<AlignWithTargetBody>();
alignment.SetTargetBody(primaryBody?.GetAttachedOWRigidbody()); alignment.SetTargetBody(primaryBody?.GetAttachedOWRigidbody());
alignment._usePhysicsToRotate = false;
alignment._localAlignmentAxis = alignmentAxis; alignment._localAlignmentAxis = alignmentAxis;
alignment._owRigidbody = body.GetComponent<OWRigidbody>();
// Have it face the right way
var currentDirection = alignment.transform.TransformDirection(alignment._localAlignmentAxis);
var targetDirection = alignment.GetAlignmentDirection();
alignment.transform.rotation = Quaternion.FromToRotation(currentDirection, targetDirection);
alignment._owRigidbody.SetAngularVelocity(Vector3.zero);
// Static bodies won't update rotation with physics for some reason // Static bodies won't update rotation with physics for some reason
// Have to set it in 2 ticks else it flings the player into deep space on spawn (#171) alignment._usePhysicsToRotate = !config.Orbit.isStatic;
// Pushed to 3 frames after system is ready, bc spawning takes 2 frames, this is hurting my brain too much to try to improve the numbers idc
if (!config.Orbit.isStatic) Delay.RunWhen(() => Main.IsSystemReady, () => Delay.FireInNUpdates(() => alignment._usePhysicsToRotate = true, 3));
} }
if (config.Base.centerOfSolarSystem) if (config.Base.centerOfSolarSystem)

View File

@ -41,7 +41,7 @@ namespace NewHorizons.Handlers
if (matchInitialMotion != null) UnityEngine.Object.Destroy(matchInitialMotion); if (matchInitialMotion != null) UnityEngine.Object.Destroy(matchInitialMotion);
// Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent // Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent
Delay.StartCoroutine(SpawnCoroutine(10)); Delay.StartCoroutine(SpawnCoroutine(30));
} }
} }