My game, Fleet, has started its BETA testing phase recently and my number 1 issue is lag at the moment. The game currently has AA guns, Single, Double, and Tripple barrel turrets for ships. There are two weapons, a rifle, and a pistol.
The tools:
When the player fires an event for the gun, the server creates a ray from the tool to the target. It then checks if there are other players within a 200 stud radius; If so, it tells those clients to make a bullet via the client, showing the person who fired.
The AA guns/Turrets:
The player would trigger the fire event, which would then tell the server to create a bullet on the server.
I obviously have checks and debounces to prevent spamming. However, if I were to convert all the AA guns/Turrets using the method I use for the tools, would this prevent lag drastically?
When I say lag, It’s more of a server delay I mean. Yeah, it seems whenever I get those slight server delay here and there, the render seems to be what might be the cause of it. But again, that’s here and there though.
Yes, this could likely help reduce lag however it would still leave the original player who fired it with some input delay. Here’s a method I use for guns in my newer games:
Try drawing a bullet on the client who fired it first so the original client feels like the input went through before it actually did, then fire the event to replicate it to other clients. To prevent easy exploit abuse though, don’t base the servers check on what the first client drew and have the server still fire the ray itself. That may create some slight inaccuracies between the original client and the server, but I feel it’s worth not letting exploiters automatically auto aim everyone on the server.
Also, rather than looping through all players to find players within the radius, why not just fireallclients the replication and have the clients check for that themselves?
(Also, include a variable within the client request that contains the original player who fired it so that player can ignore the request and not draw it twice.)
Right on man! This will take me some time, about a day to convert everything. I’ll reply back to this post telling you guys how it went, whether or not it made a difference.
This is the current method I am using:
Client fires the Fire event to the turret.
Turret then makes the bullet on the server and uses a touched event for the bullet to deal damage.
What I’m going to do:
The client fires the Fire event to the turret.
The turret then uses raycast, fires event to all clients. (Handles the damage with raycast)
Client gets event, checks if they are close enough, makes bullet on their side.
Awesome, dude. However, don’t forget to have the client that initially fires the event draw a bullet themselves on their own client so the input doesn’t feel delayed.
(and of course make sure that when they fireallclients after the original client ignores it if its their bullet)