This commit is contained in:
2026-05-12 21:43:03 +07:00
parent 5025383676
commit a1e52f95ad
12 changed files with 995 additions and 32 deletions

View File

@@ -26,7 +26,6 @@ namespace OnlyScove.Scripts
[Networked] public bool IsGrounded { get; set; }
[Networked] public bool WasGrounded { get; set; }
[Networked] public float VelocityY { get; set; }
[Networked] public Vector3 NetworkedPosition { get; set; }
private CharacterController controller;
@@ -48,10 +47,6 @@ namespace OnlyScove.Scripts
if (controller != null && controller.enabled)
{
controller.Move(velocity * deltaTime);
if (Object != null && Object.HasStateAuthority)
{
NetworkedPosition = transform.position;
}
}
}

View File

@@ -92,18 +92,13 @@ namespace OnlyScove.Scripts
public override void Spawned()
{
InitializePlayer();
if (Object != null && !Object.HasInputAuthority && Runner.IsClient)
{
if (Controller != null) Controller.enabled = false;
}
}
private void InitializePlayer()
{
if (currentState == null) SwitchState(new PlayerIdleState(this));
bool isLocal = (Object != null && Object.HasInputAuthority) || (Runner == null || !Runner.IsRunning);
bool isOffline = Runner == null || !Runner.IsRunning;
if (isOffline || (Object != null && Object.HasInputAuthority))
if (isLocal)
{
Local = this;
CameraController cameraController = GameObject.FindAnyObjectByType<CameraController>();
@@ -116,6 +111,7 @@ namespace OnlyScove.Scripts
if (Input != null)
{
Input.enabled = true; // Ensure local input is enabled
Input.OnNextInteractEvent -= Interaction.NextInteract;
Input.OnNextInteractEvent += Interaction.NextInteract;
Input.OnPreviousInteractEvent -= Interaction.PreviousInteract;
@@ -124,6 +120,16 @@ namespace OnlyScove.Scripts
if (Controller != null) Controller.enabled = true;
}
else
{
// Disable input for proxies to prevent "Input Overlap"
if (Input != null) Input.enabled = false;
// On clients, proxies don't need CharacterController enabled
if (Runner != null && Runner.IsClient && Controller != null) Controller.enabled = false;
}
if (currentState == null) SwitchState(new PlayerIdleState(this));
}
private void OnDestroy()
@@ -181,6 +187,7 @@ namespace OnlyScove.Scripts
IsSprintHeld = UnityEngine.Input.GetKey(KeyCode.LeftShift);
}
// Only run logic if we have Input Authority (Local Player) or State Authority (Server simulating Player)
if (!isRunning || (Object != null && Object.IsValid && (Object.HasInputAuthority || Runner.IsServer)))
{
if (hasControl)
@@ -197,11 +204,7 @@ namespace OnlyScove.Scripts
bool isRunning = Runner != null && Runner.IsRunning;
if (isRunning && Object != null && Object.IsValid && !Object.HasInputAuthority)
{
// Smooth interpolation for proxies
if (Movement.NetworkedPosition != Vector3.zero)
{
transform.position = Vector3.Lerp(transform.position, Movement.NetworkedPosition, Runner.DeltaTime * 15f);
}
// Note: We now rely on NetworkTransform component for position syncing
UpdateAnimator(Runner.DeltaTime);
}
else if (!isRunning)