Remote-driven car: keep attached parts on unbreakable joints instead of switching them kinematic (that broke the joints and the car fell apart); passenger range measured to the car body

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 09:18:39 +02:00
co-authored by Claude Opus 5.5
parent ce4aa7e0a6
commit bdd86336c2
2 changed files with 41 additions and 27 deletions
+18 -2
View File
@@ -11,7 +11,7 @@ namespace MSCO
/// </summary>
public class Passenger
{
const float EnterRange = 5f; // so nah muss man am Fahrzeug stehen (Abstand zur Fahrzeugmitte)
const float EnterRange = 3f; // so nah muss man an der Karosserie stehen
const float CenterSeatThreshold = 0.2f;
const float BehindCenterSeat = 0.7f;
const float ExitSideOffset = 1.4f; // beim Aussteigen so weit neben den Sitz
@@ -44,7 +44,7 @@ namespace MSCO
float nearest = float.MaxValue;
foreach (SyncedBody b in driven)
{
float d = (b.Rb.worldCenterOfMass - player.position).sqrMagnitude;
float d = DistanceToVehicleSq(b, player.position);
nearest = Mathf.Min(nearest, d);
PlayerInfo owner;
if (!players.TryGetValue(b.OwnerId, out owner) || owner.Avatar == null) continue;
@@ -69,6 +69,22 @@ namespace MSCO
return "Riding as passenger (press again to get out)";
}
/// <summary>
/// Abstand zur nächsten Stelle der Karosserie (Collider), nicht zum Schwerpunkt - den legt MSC teils weit weg,
/// dann hieß es "26 m entfernt", obwohl man direkt an der Tür stand.
/// </summary>
static float DistanceToVehicleSq(SyncedBody b, Vector3 point)
{
float best = (b.Rb.position - point).sqrMagnitude;
foreach (Collider c in b.Rb.GetComponentsInChildren<Collider>())
{
if (c == null || !c.enabled || c.isTrigger) continue;
float d = (c.bounds.ClosestPoint(point) - point).sqrMagnitude;
if (d < best) best = d;
}
return best;
}
/// <summary>Nach der Physik (LateUpdate): Spieler auf den Sitz setzen und mitdrehen.</summary>
public void LateUpdate(Transform player, Camera cam, ObjectSync objects)
{