#Problem moving on the client
1 messages · Page 1 of 1 (latest)
ok
[1] using System.Collections;
[2] using System.Collections.Generic;
[3] using UnityEngine;
[4] using Unity.Netcode;
[5]
[6] public class ServerPlayer : NetworkBehaviour
[7] {
[8]
[9] [SerializeField] float speed = 10f;
[10] [SerializeField] CharacterController cc;
[11] [SerializeField] Transform playerTransform;
[12] private _PlayerInput PInput;
[13]
[14] private void Start()
[15] {
[16] PInput = new();
[17] PInput.Enable();
[18] }
[19]
[20] private void Update()
[21] {
[22] Vector2 MoveInput = PInput.Player.Movement.ReadValue<Vector2>();
[23]
[24] if (IsServer && IsLocalPlayer)
[25] {
[26] Move(MoveInput);
[27] }
[28] else if (IsClient && IsLocalPlayer)
[29] {
[30] //MoveServerRpc(MoveInput);
[31] MoveServerRpc(MoveInput);
[32] }
[34] }
[35]
[36] private void Move(Vector2 _Input)
[37] {
[38] Vector3 calcMove = _Input.x * playerTransform.right + _Input.y * playerTransform.forward;
[39]
[40] cc.Move(calcMove * speed * Time.deltaTime);
[41] }
[42]
[43] [ServerRpc]
[44] private void MoveServerRpc(Vector2 _Input)
[45] {
[46] Move(_Input);
[47] }
[48]
[49] }
Make sure you have a netowrk transform on the player. I believe you'll have to disable the character controller on the remote players on the clients