From 23429ec096912c0bf4a2036ba2ac7f0bfdd23704 Mon Sep 17 00:00:00 2001 From: dal4segno Date: Wed, 25 Feb 2026 21:40:50 +0900 Subject: [PATCH] =?UTF-8?q?=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=8F=99=EC=86=8D=EB=8F=84=EA=B0=80=202?= =?UTF-8?q?=EB=B0=B0=EC=9D=B8=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로컬 컨트롤러를 제거하고 네트워크 컨트롤러만 남겨둠 --- Assembly-CSharp.csproj | 1 - Assets/Scripts/NetworkPlayerController.cs | 84 +++++++++++++++-------- Assets/Scripts/PlayerController.cs | 40 ----------- Assets/Scripts/PlayerController.cs.meta | 11 --- 4 files changed, 55 insertions(+), 81 deletions(-) delete mode 100644 Assets/Scripts/PlayerController.cs delete mode 100644 Assets/Scripts/PlayerController.cs.meta diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 0db9a79..6817af5 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -67,7 +67,6 @@ - diff --git a/Assets/Scripts/NetworkPlayerController.cs b/Assets/Scripts/NetworkPlayerController.cs index e019099..9ccc57b 100644 --- a/Assets/Scripts/NetworkPlayerController.cs +++ b/Assets/Scripts/NetworkPlayerController.cs @@ -165,6 +165,14 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl base.OnNetworkDespawn(); } + // 이동 동기화 설정 + private float _moveSendInterval = 0.016f; // ~60Hz 전송 + private float _moveSendTimer; + private Vector2 _lastSentMoveInput; + + // 서버 측 이동 입력 저장 + private Vector2 _serverMoveInput; + void Update() { // 서버에서 체력 자연 회복 처리 @@ -185,47 +193,65 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl // 액션/상호작용 중이면 이동 불가 var attackAction = GetComponent(); var playerInteraction = GetComponent(); - + bool isActionBlocked = (attackAction != null && attackAction.IsAttacking) || (playerInteraction != null && playerInteraction.IsInteracting); - - if (isActionBlocked) + + if (isActionBlocked) { - // 서버에 이동 중지 알림 (애니메이션 포함) - MoveServerRpc(Vector2.zero); + // 서버에 이동 중지 알림 + if (_lastSentMoveInput != Vector2.zero) + { + _lastSentMoveInput = Vector2.zero; + MoveServerRpc(Vector2.zero); + } return; } _moveInput = _inputActions.Player.Move.ReadValue(); - - // 서버에 이동 요청 전송 (애니메이션 포함) - MoveServerRpc(_moveInput); + + // 일정 간격으로만 서버에 전송 (네트워크 부하 감소) + _moveSendTimer += Time.deltaTime; + if (_moveSendTimer >= _moveSendInterval || _moveInput != _lastSentMoveInput) + { + _moveSendTimer = 0f; + _lastSentMoveInput = _moveInput; + MoveServerRpc(_moveInput); + } + } + + void FixedUpdate() + { + // 서버에서만 물리 이동 처리 + if (!IsServer) return; + if (_currentHealth.Value <= 0) return; + + Vector3 move = new Vector3(_serverMoveInput.x, 0, _serverMoveInput.y).normalized; + + if (move.magnitude >= 0.1f) + { + Quaternion targetRotation = Quaternion.LookRotation(move); + transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime); + + if (_controller != null) + { + float moveSpeed = _playerStats?.GetMoveSpeed() ?? 5f; + _controller.Move(move * moveSpeed * Time.fixedDeltaTime); + } + } + + // 애니메이션 업데이트 + if (_networkAnimator != null) + { + _networkAnimator.Animator.SetFloat("MoveSpeed", move.magnitude); + } } [Rpc(SendTo.Server)] private void MoveServerRpc(Vector2 moveInput) { - // 죽었으면 이동 불가 - if (_currentHealth.Value <= 0) return; - - Vector3 move = new Vector3(moveInput.x, 0, moveInput.y).normalized; - - // NetworkAnimator로 애니메이션 동기화 - if (_networkAnimator != null) - { - _networkAnimator.Animator.SetFloat("MoveSpeed", move.magnitude); - } - - if (move.magnitude >= 0.1f) - { - Quaternion targetRotation = Quaternion.LookRotation(move); - transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); - - if (_controller != null) - { - _controller.Move(move * (_playerStats?.GetMoveSpeed() ?? 5f) * Time.deltaTime); - } - } + // 서버에 입력만 저장, 실제 이동은 FixedUpdate에서 처리 + _serverMoveInput = moveInput; } #region ITeamMember Implementation diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs deleted file mode 100644 index 7590be6..0000000 --- a/Assets/Scripts/PlayerController.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Northbound; -using UnityEngine; - -[RequireComponent(typeof(Rigidbody))] -public class PlayerController : MonoBehaviour -{ - [Header("Movement Settings")] - [SerializeField] private float moveSpeed = 5f; - - private Rigidbody rb; - private Vector3 moveDirection; - private PlayerInteraction playerInteraction; - - void Start() - { - rb = GetComponent(); - rb.constraints = RigidbodyConstraints.FreezeRotation; - playerInteraction = GetComponent(); - } - - void Update() - { - if (playerInteraction != null && playerInteraction.IsInteracting) - return; - - float horizontal = Input.GetAxisRaw("Horizontal"); - float vertical = Input.GetAxisRaw("Vertical"); - - moveDirection = new Vector3(horizontal, 0f, vertical).normalized; - } - - void FixedUpdate() - { - rb.linearVelocity = new Vector3( - moveDirection.x * moveSpeed, - rb.linearVelocity.y, - moveDirection.z * moveSpeed - ); - } -} diff --git a/Assets/Scripts/PlayerController.cs.meta b/Assets/Scripts/PlayerController.cs.meta deleted file mode 100644 index f86b8ed..0000000 --- a/Assets/Scripts/PlayerController.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7a3e5b8c4d2f1a9e6b0c3d7e8f1a2b3c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: