Hello!
Currently I am working on Lag compensation for Multiplayer. And I’ve hit a wall.
Basically I am storing position of certain objects to an array ever so often and then assosiate the current frameId with it.
So When a client says Shoot. they also specify what their frameId is.
The server then has to roll back the state to what it was at x frameId. Then do some raycasts etc. Then move it back again.
How would this be achieved?
I’ve looked into Physics.Simulate, WaitForFixedUpdate. But it doesn’t seem to be a very fitting solution for me.
This is what I basically want to do:
public static void Simulate(int frameId, Action action)
{
for (int i = 0; i < SimulationObjects.Count; i++)
{
//Moves the objects to the position they had wat the frameId specified.
SimulationObjects[i].SetStateTransform(frameId);
}
//This is where I do raycasts etc.
action.Invoke();
for (int i = 0; i < SimulationObjects.Count; i++)
{
//This just moves the objects to the position they were at from the begining
SimulationObjects[i].ResetStateTransform();
}
}