Hello,
I am using this Kinematic Character Control package
I setup some Character Controls and all looks like it works fine in local. I am trying to setup some basic Networking.
I installed Network for Gameobject and did the following on my scripts
using Unity.Netcode;
using UnityEngine;
public struct PlayerCharacterInputs : INetworkSerializable
{
public float MoveAxisForward;
public float MoveAxisRight;
public float LookAxisUp;
public float LookAxisRight;
public bool Jump;
public bool Crouch;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref MoveAxisForward);
serializer.SerializeValue(ref MoveAxisRight);
serializer.SerializeValue(ref LookAxisUp);
serializer.SerializeValue(ref LookAxisRight);
serializer.SerializeValue(ref Jump);
serializer.SerializeValue(ref Crouch);
}
}
[RequireComponent(typeof(VirtualController))]
public class PlayerInputHandler : NetworkBehaviour
{
private InputManager inputManager;
private VirtualController virtualController;
private void Awake()
{
inputManager = InputManager.Instance;
virtualController = GetComponent<VirtualController>();
}
// Update is called once per frame
void Update()
{
if (!IsOwner) return;
PlayerCharacterInputs inputs = GetInputs();
virtualController.UpdateInputs(inputs);
SendInputToServerServerRpc(inputs);
}
[ServerRpc]
public void SendInputToServerServerRpc(PlayerCharacterInputs inputs)
{
virtualController.UpdateInputs(inputs);
}
public void ProcessInputsOnServer(PlayerCharacterInputs inputs)
{
virtualController.UpdateInputs(inputs);
}
public PlayerCharacterInputs GetInputs()
{
return new PlayerCharacterInputs
{
MoveAxisForward = inputManager.GetMovement().x,
MoveAxisRight = inputManager.GetMovement().y,
LookAxisRight = inputManager.GetLook().x,
LookAxisUp = inputManager.GetLook().y,
Jump = inputManager.IsJumpingThisFrame(),
Crouch = inputManager.IsCrouching()
};
}
}
Basically, I send all input from client to the server, and I let the server execute the same logic. I am totally unsure if it s correct approach for now, but it s how I would like to start setting up things.
Now, I also setup the Player Gameobject like this
On the host, I can move and see both player move, on the client, I only see the client move not the host. Also, on the host, the starting position and after movement position is completely off, the movement are fine, but the final position is completely off.
I am unsure why, from my understanding, I should be able to process the input on the server, move the transform and resync the client with a treshold position if it missmatch. But currently nothing sync at all.
Do you have potential idea for fixing ?
EDIT : I have my network player in the NetworkManager’s “Player Prefab” field