prediction for a single object, very basic prototype
video1: https://discord.com/channels/809535064551456888/891066507910578186/914670314582065162
video2: https://discord.com/channels/809535064551456888/891066507910578186/929434874195091536
The PredictionManager class sets up the the client side prediction. It will set up the simulation automatically based on the physicsMode, if local physics is selected PredictionManager will need to be in the correct scene when it's Start method is called by unity.
SetPredictionSimulation can be used to set the set custom simulation. Giving a DefaultPredictionSimulation will allow you to use local physics in a scene that the PredictionManager is not in.
Objects must have a PredictionBehaviour on the object to be effected by client side prediction.
For a behaviour to send inputs to the server it must override the HasInput property and return true.
Input functions:
GetInputcalled once per tick on client, should return inputs for the current tickApplyInputcalled client and server before the tick is simulated. Used to apply inputs to an object, eg add force to rigid based on WASD keys. For inputs like jumping or single frame actions you should compare the inputs to the previous ones to see if a button was pressed this tick.MissingInputcalled on the server if input is missing for a tick. This can be used to continue inputs that were previously received, most of the time this will work because user inputs will be almost always the same frame to frame.previousandpreviousTickare the values from the last received input, if 2 inputs have been missed they will be from N-2 tick. thecurrentTickis the tick that the inputs are missing for.
ApplyStatecall on client to set the state of the object. This should be used to set objects position, rotation or other values.GatherStatecalled on server and client to get the state from the object.NetworkFixedUpdatecalled on server and client, called once per tick and durning resimulation on client. Should be used to modify the state, For example adding a force to a rigidbody.ResimulationTransitioncalled on client to correct the resimulation. If empty the client will appear as if it is snapped to latest resimulation state. To move out this correct you can Lerp between previous and new state and callApplyState.