I'm using a modified version of the task scheduler from the tower defense video to make a FPS game. There are two ways I can go about doing hit detection:
Client side: The client raycasts and sends the raycast result to the server
Server side: The server uses the client's camera rotation and the position of the character and does hit detection server side
The issue I'm having is that client side is easily exploited and server side is very inaccurate as there really is no way to have accurate lag compensation. I want to try using the task scheduler to create "snapshots" of the game similar to how Valve does it and use that to rewind to the tick that the client fired at but I have no idea how to go about doing this.
Here is an article about how Valve handles this, there was a better one but I can't find it anywhere: https://developer.valvesoftware.com/wiki/Lag_Compensation
Valve only stores up to one full second of snapshots before erasing them from memory. I am unsure how to go about storing these snapshots in an efficient way. Here are some of my ideas:
- Use a Linked/Hybrid List and have a cap on the amount of entries. Once the cap is met, remove the last entry and enter the first entry.
- Have an array indexed by the tick. Ex:
Snapshots[tickNumber] = snapshot - Just use client sided hit detection
The snapshots only include player positions, however I am unsure how to go about creating these snapshots and what to put in it. Would I need to manually go in and write down the CFrame of each and every limb on the character? I feel like this would exponentially use up a lot of valuable server memory but I'm not sure. If there are 50 players in a server (extreme example), 32 ticks per second, and up to one second of snapshots, that's 32 snapshots for 50 players for 6 limbs. 32 * 50 * 6 = 9600 separate CFrames stored in a Linked/Hybrid list or an array. I feel like that would hog memory.
If anyone has any ideas or wants to discuss this let me hear it