Join: replay part actions first, then rescan and place objects (detached parts no longer stuck in the car); rescan right after remote disassembly; lift out bodies that keep getting flung

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 08:52:53 +02:00
co-authored by Claude Opus 5.5
parent 8346cd9b09
commit 647acda46c
2 changed files with 58 additions and 7 deletions
+28 -4
View File
@@ -31,6 +31,9 @@ namespace MSCO
// wird dann NICHT als loses Objekt synchronisiert - sonst reißt das Gelenk und das Teil fliegt weg
public bool Attached;
public float NextAttachCheck;
// Wie oft kurz hintereinander weggeschleudert (steckt es in etwas fest?)
public int RunawayCount;
public float RunawayWindowStart;
public Vector3 TargetPos;
public Quaternion TargetRot;
@@ -528,13 +531,27 @@ namespace MSCO
if (rb.isKinematic || rb.velocity.sqrMagnitude < RunawaySpeed * RunawaySpeed) return;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
if (IsLocal(b) && b.LastSentTime > 0f && IsValidPose(b.LastSentPos, b.LastSentRot))
// Mehrmals kurz hintereinander: das Objekt steckt in etwas fest (z.B. abgebautes Teil im Auto).
// Dann nicht wieder an dieselbe Stelle setzen, sondern nach oben heraus heben.
if (Time.time - b.RunawayWindowStart > 5f) { b.RunawayWindowStart = Time.time; b.RunawayCount = 0; }
b.RunawayCount++;
bool stuck = b.RunawayCount >= 3;
if (stuck)
{
rb.transform.position = AboveGround(b.LastSentPos, rb.transform);
Bounds bounds = new Bounds(rb.worldCenterOfMass, Vector3.zero);
foreach (Collider c in rb.GetComponentsInChildren<Collider>()) bounds.Encapsulate(c.bounds);
rb.transform.position += Vector3.up * (bounds.size.y + 1.5f);
b.RunawayCount = 0;
}
else if (IsLocal(b) && b.LastSentTime > 0f && IsValidPose(b.LastSentPos, b.LastSentRot))
{
rb.transform.position = b.LastSentPos;
rb.transform.rotation = b.LastSentRot;
}
else rb.transform.position = AboveGround(rb.position, rb.transform);
ModConsole.Warning("[MSCO] Stopped " + b.RootName + " - it was flung away by the physics");
b.NoMotionClaimUntil = Time.time + HandoverCooldown;
if (b.RunawayCount <= 1 || stuck)
ModConsole.Warning("[MSCO] Stopped " + b.RootName + " - it was flung away by the physics" + (stuck ? " (stuck, lifted out)" : ""));
}
/// <summary>
@@ -745,6 +762,13 @@ namespace MSCO
// ---------------------------------------------------------------- Registrierung
/// <summary>Sofort nach neuen Objekten suchen (z.B. nach dem Nachspielen von Montage-Aktionen).</summary>
public void ScanNow()
{
Scan();
nextScan = Time.time + ScanInterval;
}
/// <summary>Neue Rigidbodies suchen (gekaufte Items, abmontierte Teile ...).</summary>
void Scan()
{