How can I prevent inaccurate Raycasting due to delay from the server?

gun
In the gif above you see a simple gun I made. It works by having the client send positional data to the server where the server then draws the Ray with the data aforementioned. The problem with this is that it takes a small amount of time for the data to reach the server, so if the player is moving then the server will draw the Ray using inaccurate data.

My question is: how can this delay be reduced so that the Ray always appears to be leaving the gun such that it does not look like it’s coming out of thin air?

I have tried drawing two rays - one on the client and one on the server, however this effectively doubles the amount of data being processed which I believe is unnecessary. Similarly, the fix would only apply to the client, so the player would still see other player’s rays “floating”.

I am open to ideas! :slight_smile:

1 Like

This will help you understand the basics of first person shooters and how the data is handled. Now for your rays the client should do the ray itself and let the server know if it has a hit, now the server does checks to prove whether or not the actual hit is valid or not. Now it comes at a cost of making it extremely hard to deal with exploiters and spoofing the information.


To the OP, you can look into how Valve does lag compensation . Fair warning, it is a pretty hefty document.

Quote from - Kampfkarren

8 Likes