Hello all, after searching for some time I have yet come across a solution to this problem so I’m making my own post.
To put it simply I have basic spells I want to replicate across all clients. I’ve seen the system talked about countless times on other post:
Player uses a skill, creates it locally and fires to the server
Server validates the skill and then creates it’s own version
Server then fires to all clients their “dummy” skill so they get the visuals too
(If this isn’t even the correct way to go about it please correct me)
The problem I’m having is syncing step 1 and 2. The client instantly creates the skill and it takes some time for the server to create its own too. Since the server handles the hit detection it causes a delay from when the local skill hit to when the server skill hit. The client can also see their skill hit but the server’s version might not creating an undesirable experience.
So, my question is how do you combat this and keep the two synced? I’ve seen vague replies like sync the client and server times. That doesn’t help at all. If there are examples, articles, more in depth solutions or sudo that would be greatly appreciated.
But in actuality, what you can do is basically timestamp your client event. If your client time and server time is the same (synced) then you can calculate the delay before the event was received. From what I see in your video, it looks like the effect is simply just setting the position of the ball in front of the character and applying a constant velocity. Since velocity is constant in this case, the only correction factor needed is the position of the ball. Instead of starting the ball right in front of the player, you can instead spawn it in front of the player + a correction factor. Your correction factor can simply just be velocity*lag_time, as this will be where the ball should be if it was fired at the original client time.
Keep in mind that you have to somewhat verify if these times are correct, as players can abuse it if the discrepancy is allowed to be too great (lag switching, exploiting, etc). Lag compensation in video-games are exploited pretty heavily; CS:GO being an example. The exact method of determining delay is up to you. You can also use different kinematic models if your spell has different movement paths/velocities.
jody pretty much covered what I’d do. But one thing I would say specifically for player ability kind of things is that you can rely just on the server but have visual effects to make it seem far more natural.
For example, if a player is launching a fire ball, you could have him do a little charge up with his arm (as if he is getting ready to cast) on the client while the information is being sent to the server. Of course this is only for more specific cases but it’s certainly something I’ve found very helpful for making things seem more smooth.
i might be sounding really dumb here but would it be possible for the server to create the dummy projectile first and fire to all clients as opposed to letting the caster create their own version before firing to the server? there might be something inherently bad about this method but i feel like this should make things more consistent, idk.
Why have the client create it at all? Just have the client activate the skill and then tell the server to do it. I’m pretty sure that if the server creates it. All clients can see it without having to fire an event to all clients. No matter what there will always be some form of delay between a client action and the server. This is why most gamers have the best internet connections they can get, to reduce these delays. Plus isn’t it considered bad practice to allow the client to create anything? I’m still a noob with roblox really but I never allow my client scripts to create or handle anything other than submitting user input or handling animations that have no effect on game mechanics. Maybe I’m doing it wrong Idk.
The point of asking clients to generate the visuals is to greatly reduce server lag, so the server only handles the “mechanics” aspect while the client handles all the fancy looking schmuck that could kill a server.
I would understand that if the visual was purely for the clients sake. But in this case it seems like you want all the clients to see it and the server has to do it anyways. So why compound the workload? If the server has to do it no matter what then your doubling what the client has to process, both reading the server implementation as well as processing it themselves.
Ah thank you! I usually saw “Sync your client and server times” with zero explanation of what that meant to do. So, if I understand this correctly send the tick() timestamp from the client when they use a skill and of course fire the client’s skill instantly. Then on the server spawn the skill, multiply it’s velocity by the lag_time which is the tick() sent and add that to it’s position? Then I’ll have some checks in place to make sure the tick() isn’t ridiculous.
Yes, in this example that’s true because I’m only firing a single sphere on both the client and sever. As skills get more complex you don’t want the server to instance multiple parts and effects, ideally you want the server to be creating and handling a single part like the hitbox. Then have the clients add on all the “pizazz” so to speak.
Oh that’s a smooth idea. I haven’t done animations yet but if I could kind of compensate for the server lag with a firing animation that would help eliminate the delayed look. The problem would be figuring out exactly how much time the sever needs to receive that information and spawn it’s version.