mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-10 03:40:01 +00:00
precalculate leash length immediately and use that
This commit is contained in:
parent
1ee4de154a
commit
08d7671234
@ -72,12 +72,10 @@ namespace QSB.MeteorSync.Events
|
||||
{
|
||||
qsbFragment.DetachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector,
|
||||
MeteorManager.WhiteHoleVolume._whiteHoleProxyShadowSuperGroup);
|
||||
qsbFragment.Body.gameObject.AddComponent<DebrisLeash>().Init(MeteorManager.WhiteHoleVolume._whiteHoleBody,
|
||||
msg.LeashLength);
|
||||
}
|
||||
else if (msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole)
|
||||
{
|
||||
qsbFragment.DetachableFragment.EndWarpScaling();
|
||||
qsbFragment.LeashLength = msg.LeashLength;
|
||||
qsbFragment.Body.gameObject.AddComponent<DebrisLeash>()
|
||||
.Init(MeteorManager.WhiteHoleVolume._whiteHoleBody, qsbFragment.LeashLength);
|
||||
}
|
||||
else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace QSB.MeteorSync.Patches
|
||||
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity<QSBMeteorLauncher>(__instance);
|
||||
|
||||
MeteorController meteorController = null;
|
||||
QSBMeteor qsbMeteor = null;
|
||||
QSBMeteor qsbMeteor;
|
||||
|
||||
bool MeteorMatches(MeteorController x)
|
||||
{
|
||||
@ -107,11 +107,60 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.MoveByDistance))]
|
||||
public static bool MoveByDistance(DebrisLeash __instance,
|
||||
float distance)
|
||||
{
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance._detachableFragment._fragmentIntegrity);
|
||||
|
||||
if (__instance.enabled)
|
||||
{
|
||||
var vector = __instance._attachedBody.GetPosition() - __instance._anchorBody.GetPosition();
|
||||
var d = Mathf.Min(distance, qsbFragment.LeashLength - vector.magnitude);
|
||||
__instance._attachedBody.SetPosition(__instance._anchorBody.GetPosition() + vector.normalized * d);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Impact))]
|
||||
public static bool Impact(MeteorController __instance,
|
||||
[HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.FixedUpdate))]
|
||||
public static bool FixedUpdate(DebrisLeash __instance)
|
||||
{
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance._detachableFragment._fragmentIntegrity);
|
||||
|
||||
if (!__instance._deccelerating)
|
||||
{
|
||||
var num = Vector3.Distance(__instance._attachedBody.GetPosition(), __instance._anchorBody.GetPosition());
|
||||
var num2 = Mathf.Pow(__instance._attachedBody.GetVelocity().magnitude, 2f) / (2f * __instance._deccel);
|
||||
var vector = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity();
|
||||
if (num >= qsbFragment.LeashLength - num2 && vector.magnitude > 0.1f)
|
||||
{
|
||||
__instance._deccelerating = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var vector2 = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity();
|
||||
var velocityChange = -vector2.normalized * Mathf.Min(__instance._deccel * Time.deltaTime, vector2.magnitude);
|
||||
if (velocityChange.magnitude < 0.01f)
|
||||
{
|
||||
__instance._attachedBody.SetVelocity(__instance._anchorBody.GetVelocity());
|
||||
__instance._deccelerating = false;
|
||||
if (__instance._detachableFragment != null)
|
||||
{
|
||||
__instance._detachableFragment.ComeToRest(__instance._anchorBody);
|
||||
}
|
||||
__instance.enabled = false;
|
||||
return false;
|
||||
}
|
||||
__instance._attachedBody.AddVelocityChange(velocityChange);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,5 +155,62 @@ namespace QSB.MeteorSync.Patches
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBFragmentDamage, qsbFragment, damage);
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.MoveByDistance))]
|
||||
public static bool MoveByDistance(DebrisLeash __instance,
|
||||
float distance)
|
||||
{
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance._detachableFragment._fragmentIntegrity);
|
||||
|
||||
if (__instance.enabled)
|
||||
{
|
||||
var vector = __instance._attachedBody.GetPosition() - __instance._anchorBody.GetPosition();
|
||||
var d = Mathf.Min(distance, qsbFragment.LeashLength - vector.magnitude);
|
||||
__instance._attachedBody.SetPosition(__instance._anchorBody.GetPosition() + vector.normalized * d);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.FixedUpdate))]
|
||||
public static bool FixedUpdate(DebrisLeash __instance)
|
||||
{
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance._detachableFragment._fragmentIntegrity);
|
||||
|
||||
if (!__instance._deccelerating)
|
||||
{
|
||||
var num = Vector3.Distance(__instance._attachedBody.GetPosition(), __instance._anchorBody.GetPosition());
|
||||
var num2 = Mathf.Pow(__instance._attachedBody.GetVelocity().magnitude, 2f) / (2f * __instance._deccel);
|
||||
var vector = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity();
|
||||
if (num >= qsbFragment.LeashLength - num2 && vector.magnitude > 0.1f)
|
||||
{
|
||||
__instance._deccelerating = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var vector2 = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity();
|
||||
var velocityChange = -vector2.normalized * Mathf.Min(__instance._deccel * Time.deltaTime, vector2.magnitude);
|
||||
if (velocityChange.magnitude < 0.01f)
|
||||
{
|
||||
__instance._attachedBody.SetVelocity(__instance._anchorBody.GetVelocity());
|
||||
__instance._deccelerating = false;
|
||||
if (__instance._detachableFragment != null)
|
||||
{
|
||||
__instance._detachableFragment.ComeToRest(__instance._anchorBody);
|
||||
}
|
||||
__instance.enabled = false;
|
||||
return false;
|
||||
}
|
||||
__instance._attachedBody.AddVelocityChange(velocityChange);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
{
|
||||
ObjectId = id;
|
||||
AttachedObject = attachedObject;
|
||||
DetachableFragment = AttachedObject.GetRequiredComponent<DetachableFragment>();
|
||||
DetachableFragment = AttachedObject.GetComponent<DetachableFragment>();
|
||||
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
@ -24,7 +24,8 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
|
||||
|
||||
public DetachableFragment DetachableFragment;
|
||||
public bool IsThruWhiteHole => DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
|
||||
public bool IsThruWhiteHole => DetachableFragment != null &&
|
||||
DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
|
||||
public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody :
|
||||
Locator._brittleHollow._owRigidbody;
|
||||
public OWRigidbody Body => IsThruWhiteHole ? AttachedObject.transform.parent.parent.GetAttachedOWRigidbody() : null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user