Last active
November 25, 2021 10:46
-
-
Save ChristianTucker/d5ec85a59f449871742d1668734d0807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!