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. | |
} | |
} |
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
@hellostorman I'm not really sure what your question is, this was intended just to be Psuedo. In this example
Keybinds
is intended to be used everywhere, andKeybind
has no use and should be refactored toKeybinds
. You should create a collection that keeps track of which keys are pressed and when they were pressed so you can do lookups on key combinations as well as how long keys have been held down. You should look into bitmasks and enums to properly determine how to return the bound keys.For example..
and then you can declare these such as
You can use bitwise operators to add or remove data from the byte (or short/int/long depending on the amount of flags you use)