im making a hitbox on the server for the player to see so they can rely on a accurate hitbox instead of the one on their screen
on the server the hitbox is exactly to player 1 to 1 precision (it works well enough)
on the client, they see this hitbox that is behind them
it looks glitchy
i thought making my loop faster would increase the smoothness but it didnt work and with no effect
(i made my loop at least 10 times faster or more than a loop running on every frame)
my code looks something like this
for i=1,math.ceil((20000/60)/60) do
Physics are only replicated at 20hz. You will need to do something between network replication steps to smooth the movement.
I can’t really suggest any specific solution because I’m not exactly sure what you want out of this. I personally would never do this, because it’s kind of an odd question to ask. You can’t really know exactly where the server sees you because the position will be wrong by the time it arrives at the client. You could extrapolate the position to account for that, but then your extrapolation has its own set of errors.
You’re really working with an unsolvable problem here, which is “how can I have two computers knowing the exact same information at the exact same time?”. There are all sorts of reasons this is impossible, but suffice to say it is an unsolved problem in computer science. The only real solution is to use quantum computers, which I think is a bit outside the scope of this project.
If you don’t really care that much about 100% accuracy, you should extrapolate. It will give you accurate results if you’re moving in a straight line at a constant speed, and you can even make it kind of smart so that it extrapolates curves. But an extrapolation solution will always give incorrect data when your player suddenly starts, stops, or changes direction. It also can’t account for anything the server might do, such as knock you back from an explosion.
If you don’t like that, interpolating between the previous position and the current position is a classic solution. It will give you accurate information, delayed by ~50ms-100ms, which I think kind of defeats the purpose of this whole thing. But hey, there it is.
One final solution is to do the whole thing without network replication. You can calculate the player’s ping by sending a remote function. You can also just track the player’s position on each frame. If you update your ghost such that it’s always ping/2 seconds behind the player, you’ve got a pretty solid solution. It won’t account for fluctuations in network quality, which happen literally all the time, but I think it’s the best solution out of the three.
The information is never accurate because it takes time for the information to get to the client. By the time it gets there, it is no longer accurate. You have to account for this and be clever about how you display the information.