The past 24 hours I've been working non-stop on the projectile system , and it turned out pretty good , but
i don't think it's optimized enough.
Basically it's working like that:
Player left click > Creates local sprite > Sends angle of bullet and own id to the server.
The server received the message > The server broadcasts the id of the player ( that shot ) and the angle of bullet to other peers. Once a peer receives the message from server , it creates a bullet on the player that shot ( identified by the id server sent ).
But , each weapon has it's own projectile , so - once the PEER receives the message from server , it makes a request to the database and checks the weapon of the player that shot ( by id obv.) .
This is quite a process , and i think it can be optimized a lot , tell me if there's any way of doing it.
( Locally , this process is instant , but when the server is host on a vps , there are small lags , by small i mean really fucking big )
Current in-game footage
Also , the position interpolation of the players - i have no fucking idea how to do it.
The lag is most likely because you are checking the database everytime you fire a projectile, that is a very bad idea. In the current realm client they check the projectile id through the client but you will need to add a check to see if people are cheating and spoofing their weapon through the client. This check will obviously need to be server sided.
First off, I would not suggest having the client message the database for player info. This will always be a slow process. You should load all relevant player info into the game server when they log in, then save the changes when they log off (periodically as well, if you want). The server should handle most things, and just tell the client what to display. You will most likely want different systems for ally projectiles and enemy projectiles (unless it's some pvp server, then it's a whole different ball game). For ally projectiles you really have no reason to verify anything on the client side, as long as the server is sending correct info, just display it as best as you can. Ally projectiles have no effect in the game other than visuals, so it's okay if they are a bit off on the position/angle. Enemy projectiles (that are fully hit checked) are a beast to deal with, I'll can provide a write up on them if you want, but I'll pass on that for now.
Your projectile network flow should look like this:
Player Shoot -> Server -> Batching? -> Broadcast to allies
Player Shoot
Only angle info sent. The server assigns it's global id, but the shooter never needs to know his global shot id
Instead, the shooter should keep his own local projectile id counter and use that to send info regarding the shot, usually used by hit packets
The projectile object can use the player data acquired at login to determine the type of projectile shot.
Send the angle info to the server
Server
The server should receive the angle info, then create a projectile object with a unique id attached to it. The server also needs to keep track of the shooter's local id and it's equivalent global id, a simple dictionary should work.
Batching
This part is optional, but better for performance.
The server can add the projectile object to a queue system that is cleared each game tick, 20 per second usually works and feels best.
Broadcast to allies
The server should broadcast the projectile to allies (or list of projectiles if you batched the projectiles).
I would avoid sending the projectile to it's original shooter, because it is unnecessary. You should only be sending angle information paired with the player id that shot it.
Server Info
The server should update players with info about changes to other player's equips, so the other players can correctly display their ally's projectiles.
You usually send all character info when two players first meet, then send updating info as they stay in sight.
Client processing
The client should process allies projectile angle data by using previously sent ally info to determine what type and amount of projectiles should be displayed. If there is a slight desync and you receive a projectile object for an ally that has no weapon equipped, then just ignore that projectile. Remember, ally projectiles are not needed to be 100% accurate.
Let me know if you have any questions, good luck on your source!
Originally Posted by Juix
First off, I would not suggest having the client message the database for player info. This will always be a slow process. You should load all relevant player info into the game server when they log in, then save the changes when they log off (periodically as well, if you want). The server should handle most things, and just tell the client what to display. You will most likely want different systems for ally projectiles and enemy projectiles (unless it's some pvp server, then it's a whole different ball game). For ally projectiles you really have no reason to verify anything on the client side, as long as the server is sending correct info, just display it as best as you can. Ally projectiles have no effect in the game other than visuals, so it's okay if they are a bit off on the position/angle. Enemy projectiles (that are fully hit checked) are a beast to deal with, I'll can provide a write up on them if you want, but I'll pass on that for now.
Your projectile network flow should look like this:
Player Shoot -> Server -> Batching? -> Broadcast to allies
Player Shoot
Only angle info sent. The server assigns it's global id, but the shooter never needs to know his global shot id
Instead, the shooter should keep his own local projectile id counter and use that to send info regarding the shot, usually used by hit packets
The projectile object can use the player data acquired at login to determine the type of projectile shot.
Send the angle info to the server
Server
The server should receive the angle info, then create a projectile object with a unique id attached to it. The server also needs to keep track of the shooter's local id and it's equivalent global id, a simple dictionary should work.
Batching
This part is optional, but better for performance.
The server can add the projectile object to a queue system that is cleared each game tick, 20 per second usually works and feels best.
Broadcast to allies
The server should broadcast the projectile to allies (or list of projectiles if you batched the projectiles).
I would avoid sending the projectile to it's original shooter, because it is unnecessary. You should only be sending angle information paired with the player id that shot it.
Server Info
The server should update players with info about changes to other player's equips, so the other players can correctly display their ally's projectiles.
You usually send all character info when two players first meet, then send updating info as they stay in sight.
Client processing
The client should process allies projectile angle data by using previously sent ally info to determine what type and amount of projectiles should be displayed. If there is a slight desync and you receive a projectile object for an ally that has no weapon equipped, then just ignore that projectile. Remember, ally projectiles are not needed to be 100% accurate.
Let me know if you have any questions, good luck on your source!