feat(Car): wire NWH Vehicle Physics 2 — scripts only, scene/prefabs still TODO

Code-only first pass. The local Player.prefab (ball) is still in the scene
until the user creates the PlayerCar / RemoteCar prefab variants in the Editor.

New scripts:
- VehicleLocalSetup: attaches name label + colored capsule marker to the local
  vehicle, registers its Rigidbody with NetworkManager for broadcast.
- RemoteVehicleSync: snapshot interpolation for remote vehicles. Disables the
  NWH VehicleController + every WheelController + every AudioSource on init.
  Makes the rigidbody kinematic, MovePosition-driven from network. Disables all
  non-trigger colliders during the 1.5s spawn grace window to avoid ejecting
  overlapping locals at connect.

Adapted scripts:
- NetworkManager: RegisterLocalVehicle(Transform, Rigidbody) replaces the
  FindFirstObjectByType<PlayerController>() lookup. Remote spawn now wires
  RemoteVehicleSync instead of RemotePlayerController.
- LobbyUI: OnConnected drives VehicleLocalSetup.SetupLocal; OnDisconnected
  toggles NWH.VehicleController instead of PlayerController.
- GameManager.SetPlayerActive: toggles VehicleController, not PlayerController.
- DebugNetworkUI: live position read from VehicleController.vehicleRigidbody.
- ChatUI: drops PlayerController.ResetInputs() (NWH polls Input System each
  frame; no manual reset needed when chat opens).
- StatsTracker: drops dead _pc field; Rigidbody still gets resolved via
  GetComponent on the host GameObject (will be the vehicle on Car).

Frontend (deployed earlier on master): build_ball replaces pretty_build assets.
This commit is contained in:
2026-05-20 18:34:40 +02:00
parent 32becc12f9
commit 103f8859d4
14 changed files with 444 additions and 53 deletions

View File

@@ -118,25 +118,22 @@ public class LobbyUI : MonoBehaviour
var nm = NetworkManager.Instance;
if (nm != null && playerRoot != null)
{
var pc = playerRoot.GetComponentInChildren<PlayerController>(true);
if (pc != null)
var setup = playerRoot.GetComponentInChildren<VehicleLocalSetup>(true);
if (setup != null)
{
var vehicle = setup.GetComponent<NWH.VehiclePhysics2.VehicleController>();
var rb = vehicle != null ? vehicle.vehicleRigidbody : setup.GetComponent<Rigidbody>();
var localState = nm.GetLocalPlayerState();
if (localState != null)
if (localState != null && rb != null)
{
Vector3 spawnPos = new Vector3(localState.x, localState.y, localState.z);
var rb = pc.GetComponent<Rigidbody>();
if (rb != null)
{
rb.linearVelocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.position = spawnPos;
}
pc.transform.position = spawnPos;
pc.SetSpawnPosition(spawnPos);
rb.linearVelocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.position = spawnPos;
setup.transform.position = spawnPos;
}
pc.enabled = true;
pc.SetupLocalPlayer(nm.LocalPlayerName, nm.LocalPlayerColor);
if (vehicle != null) vehicle.enabled = true;
setup.SetupLocal(nm.LocalPlayerName, nm.LocalPlayerColor);
}
}
@@ -160,8 +157,8 @@ public class LobbyUI : MonoBehaviour
if (playerRoot != null)
{
var pc = playerRoot.GetComponentInChildren<PlayerController>(true);
if (pc != null) pc.enabled = false;
var vehicle = playerRoot.GetComponentInChildren<NWH.VehiclePhysics2.VehicleController>(true);
if (vehicle != null) vehicle.enabled = false;
playerRoot.SetActive(false);
}