This commit is contained in:
2026-06-30 21:19:19 +07:00
parent 30ecad1667
commit 83d4157ac6
5 changed files with 82 additions and 29 deletions

View File

@@ -36,7 +36,8 @@ namespace Hallucinate.Network
{
// Because we passed State Authority to the client in BasicSpawner,
// HasStateAuthority is true ONLY for the local player.
bool isLocal = Object.HasStateAuthority;
// Check HasInputAuthority as well so the client's character correctly activates input!
bool isLocal = Object.HasStateAuthority || Object.HasInputAuthority;
if (isLocal)
{
@@ -75,15 +76,29 @@ namespace Hallucinate.Network
public override void FixedUpdateNetwork()
{
if (Object.HasStateAuthority)
// ONLY attempt to get input if we are the Host (StateAuthority) or the owning Client (InputAuthority).
// Calling GetInput on a Proxy (someone else's character) is what causes the GetTypeKey exception!
if (Object.HasStateAuthority || Object.HasInputAuthority)
{
if (GetInput<PlayerInputData>(out var input))
{
SyncInput = input;
// Apply input locally so the Client's character actually moves predicted!
if (m_CharacterLocomotion != null)
{
m_CharacterLocomotion.InputVector = input.InputVector;
m_CharacterLocomotion.RawInputVector = input.RawInputVector;
m_CharacterLocomotion.DeltaRotation = input.DeltaRotation;
}
if (Object.HasStateAuthority)
{
SyncInput = input;
}
}
}
if (!Object.HasStateAuthority)
// If we do NOT have StateAuthority AND we do NOT have InputAuthority, it's a Proxy (remote player).
if (Object.IsProxy)
{
// Ensure look source is attached for remote players
if (m_CharacterLocomotion != null && m_CharacterLocomotion.LookSource != (ILookSource)this)
@@ -206,7 +221,7 @@ namespace Hallucinate.Network
// --- INetworkInfo Implementation ---
public bool IsLocalPlayer() => Object.HasStateAuthority;
public bool IsLocalPlayer() => Object.HasStateAuthority || Object.HasInputAuthority;
public bool IsServer() => Runner.IsServer;
// Return FALSE because we are doing Client-Authoritative movement!