dont spam recenter on spawn (#876)

- [ ] test with mods
  - [x] evacuation
  - [x] daylight savings
  - [ ] whatever the one xen found that flung you off the planet
  - [ ] other mods with tidally locked body spawn points
This commit is contained in:
Will Corby 2024-06-17 15:44:23 -07:00 committed by GitHub
commit a541d5ddce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -137,30 +137,39 @@ namespace NewHorizons.Handlers
private static IEnumerator SpawnCoroutine(int length)
{
FixPlayerVelocity();
for(int i = 0; i < length; i++)
{
FixPlayerVelocity();
FixPlayerVelocity(false); // dont recenter universe here or else it spams and lags game
yield return new WaitForEndOfFrame();
}
FixPlayerVelocity();
InvulnerabilityHandler.MakeInvulnerable(false);
}
private static void FixPlayerVelocity()
private static void FixPlayerVelocity(bool recenter = true)
{
var playerBody = SearchUtilities.Find("Player_Body").GetAttachedOWRigidbody();
var resources = playerBody.GetComponent<PlayerResources>();
SpawnBody(playerBody, GetDefaultSpawn());
SpawnBody(playerBody, GetDefaultSpawn(), recenter: recenter);
resources._currentHealth = 100f;
}
public static void SpawnBody(OWRigidbody body, SpawnPoint spawn, Vector3? positionOverride = null)
public static void SpawnBody(OWRigidbody body, SpawnPoint spawn, Vector3? positionOverride = null, bool recenter = true)
{
var pos = positionOverride ?? spawn.transform.position;
if (recenter)
{
body.WarpToPositionRotation(pos, spawn.transform.rotation);
}
else
{
body.transform.SetPositionAndRotation(pos, spawn.transform.rotation);
}
var spawnVelocity = spawn._attachedBody.GetVelocity();
var spawnAngularVelocity = spawn._attachedBody.GetPointTangentialVelocity(pos);