Passenger: player colliders off while riding (they pushed seats/parts out, physics crashed); last position: not overwritten by the save's start point, invalid positions ignored, saved when a player leaves
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+10
-1
@@ -1373,8 +1373,17 @@ namespace MSCO
|
||||
|
||||
if (r.ReadBoolean())
|
||||
{
|
||||
// Letzte eigene Position auf dem Server - nur wenn sie plausibel ist, und über den Boden gehoben
|
||||
var spawn = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
|
||||
if (localPlayer != null) localPlayer.position = spawn + Vector3.up * 0.2f;
|
||||
bool valid = !float.IsNaN(spawn.x) && !float.IsInfinity(spawn.x) && !float.IsNaN(spawn.y) && !float.IsNaN(spawn.z)
|
||||
&& Mathf.Abs(spawn.x) < 6000f && Mathf.Abs(spawn.z) < 6000f && spawn.y > -200f && spawn.y < 3000f;
|
||||
if (localPlayer != null && valid)
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(spawn + Vector3.up * 2f, Vector3.down, out hit, 6f)) spawn.y = Mathf.Max(spawn.y, hit.point.y);
|
||||
localPlayer.position = spawn + Vector3.up * 0.2f;
|
||||
ModConsole.Print("[MSCO] Back at your last position " + spawn.ToString("F0"));
|
||||
}
|
||||
}
|
||||
|
||||
// Positionen erst merken: sie werden NACH den Montage-Aktionen gesetzt. Sonst steckt ein Teil, das eine
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace MSCO
|
||||
float lastYaw;
|
||||
readonly List<Behaviour> disabled = new List<Behaviour>();
|
||||
CharacterController controller;
|
||||
// Feste Collider des Spielers, die während der Fahrt aus sind (sonst stecken sie in Sitzen und Teilen des Autos)
|
||||
readonly List<Collider> disabledColliders = new List<Collider>();
|
||||
readonly List<Rigidbody> frozenBodies = new List<Rigidbody>();
|
||||
|
||||
public bool IsRiding { get { return vehicle != null; } }
|
||||
|
||||
@@ -142,6 +145,23 @@ namespace MSCO
|
||||
controller = player.GetComponent<CharacterController>();
|
||||
if (controller != null && controller.enabled) controller.enabled = false;
|
||||
else controller = null;
|
||||
|
||||
// Der Spieler sitzt mitten im Auto: seine festen Collider würden Sitze und Teile wegdrücken
|
||||
// (Teile reißen ab, Sitze fliegen, bei Tempo stürzt die Physik ab). Wie beim echten Einsteigen: aus.
|
||||
disabledColliders.Clear();
|
||||
foreach (Collider c in player.GetComponentsInChildren<Collider>())
|
||||
{
|
||||
if (c == null || !c.enabled || c.isTrigger || c is CharacterController) continue;
|
||||
c.enabled = false;
|
||||
disabledColliders.Add(c);
|
||||
}
|
||||
frozenBodies.Clear();
|
||||
foreach (Rigidbody rb in player.GetComponentsInChildren<Rigidbody>())
|
||||
{
|
||||
if (rb == null || rb.isKinematic) continue;
|
||||
rb.isKinematic = true;
|
||||
frozenBodies.Add(rb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -149,6 +169,10 @@ namespace MSCO
|
||||
disabled.Clear();
|
||||
if (controller != null) controller.enabled = true;
|
||||
controller = null;
|
||||
foreach (Collider c in disabledColliders) if (c != null) c.enabled = true;
|
||||
disabledColliders.Clear();
|
||||
foreach (Rigidbody rb in frozenBodies) if (rb != null) rb.isKinematic = false;
|
||||
frozenBodies.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user