Marek Fix

This commit is contained in:
Dominik G.
2025-10-28 12:04:22 +01:00
parent 0cb9be4070
commit e2fa430d50
6 changed files with 402 additions and 419 deletions

View File

@@ -182,6 +182,7 @@ namespace MegaKoop.Game.Networking
var clone = Instantiate(template, spawnPosition, baseRotation, parent);
clone.name = BuildPlayerName(info, i);
AdjustSpawnToGround(clone);
ConfigureCloneForPlayer(clone, info, i);
ulong ownerSteamId = ParseSteamId(info.SteamId);
@@ -252,6 +253,25 @@ namespace MegaKoop.Game.Networking
return center + offset;
}
private void AdjustSpawnToGround(GameObject clone)
{
if (clone == null) return;
var t = clone.transform;
var cc = clone.GetComponent<CharacterController>();
Vector3 pos = t.position;
float up = 2.5f;
float down = 10f;
float radius = cc != null ? cc.radius : 0.25f;
Vector3 origin = pos + Vector3.up * up;
if (Physics.SphereCast(origin, Mathf.Max(0.05f, radius * 0.9f), Vector3.down, out RaycastHit hit, up + down, ~0, QueryTriggerInteraction.Ignore))
{
float centerY = cc != null ? cc.center.y : 0f;
float height = cc != null ? cc.height : 2f;
float targetY = hit.point.y + (height * 0.5f) - centerY + 0.02f;
t.position = new Vector3(pos.x, targetY, pos.z);
}
}
private void ConfigureCloneForPlayer(GameObject clone, LobbyPlayerInfo info, int index)
{
// Ensure network identity is deterministic across clients.