Input Handling
public struct SimpleWASDInput : IPredictedData {
public NormalizedFloat horizontal;
public NormalizedFloat vertical;
public bool jump;
public bool dash;
public void Dispose() {}
}
public class SimpleCC : PredictedIdentity<SimpleWASDInput, SimpleCCState>
{
protected override void GetFinalInput(ref SimpleWASDInput input)
{
input.horizontal = Input.GetAxisRaw("Horizontal");
input.vertical = Input.GetAxisRaw("Vertical");
input.dash = Input.GetKey(KeyCode.LeftShift);
}
protected override void UpdateInput(ref SimpleWASDInput input)
{
// Edge-triggered input is cached here and consumed once per tick
input.jump |= Input.GetKeyDown(KeyCode.Space);
}
protected override void SanitizeInput(ref SimpleWASDInput input)
{
var move = Vector2.ClampMagnitude(new Vector2(input.horizontal, input.vertical), 1f);
input.horizontal = move.x;
input.vertical = move.y;
}
}Last updated