Skip to content

Instantly share code, notes, and snippets.

@ChristianTucker
Last active November 25, 2021 10:46
Show Gist options
  • Save ChristianTucker/d5ec85a59f449871742d1668734d0807 to your computer and use it in GitHub Desktop.
Save ChristianTucker/d5ec85a59f449871742d1668734d0807 to your computer and use it in GitHub Desktop.
public class CharacterController : MonoBehaviour
{
private ClientInputState inputState;
private Vector3 velocity = Vector3.zero;
private int simulationFrame;
private void Start()
{
NetworkClient.RegisterHandler<SimulationState>(OnServerSimulationStateReceived);
}
private void Update()
{
// Only run this code on the client.
if(NetworkServer.isActive) return;
inputState = new ClientInputState
{
keysPressed = Keybinds.PressedThisFrame(),
keysDown = Keybinds.BeindHeldDown(),
keysReleased = Keybinds.ReleasedThisFrame()
};
}
private void FixedUpdate()
{
// Only run this code on the client.
if(NetworkServer.isActive) return;
// Set the inputState's simulation frame.
// NOTE: We don't do this in update, as FixedUpdate is called
// in conjunction with the physics time step, and not once per frame.
inputState.simulationFrame = simulationFrame;
// Increase the client's simulation frame.
++simulationFrame;
}
private void OnServerSimulationStateReceived(NetworkConnection connection, SimulationState message)
{
// TODO: process the server's simulation state, comparing it against the
// client's cached state for the provided simulationFrame.
}
}
@michaels-account
Copy link

I wasn't 100% sure how to ask my question since there was a lot I didn't understand, but thanks for taking the time for that reply, I'll take a look into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment