Advertisement

Projectile creation problem - it hits the player in his back?

Started by December 25, 2003 05:45 PM
1 comment, last by LeoMaheo 21 years, 1 month ago
Consider this problem: Each thing in a network game must have a unique id so it can be uniquely referenced on all clients and the server. The server is the one that generates the unique ids when new things are created. Suppose that a client player fires a projectile. In order to create a projectile, the client must tell the server "create a projectile at the server and notify each client so they also create a projectile", then the server will create a projectile and assign it a proper id and broadcast the event, and eventually the client of the player that fired the projectile will receive the broadcasted message and create a projectile (the projectile can''t be created earlier because we don''t know what id we shall assign to it before we get the server projectile creation messae). The delay from when the client asked the server to create a projectile and the time the projectile actually was created should be around one "ping". Now, assume that the client player is running fast straight forwards and that the client has authorization about the client''s position (that is, the position that the human playing at the clients sees that his player has is always correct). Then, since there is a delay of "ping" seconds from the time the player fires the projectile and the creation of the projectile, and the player is running forwards, the projectile might be created slightly behind the player! In the worst case, the projectile will hit the player in his back! What is the solution to this problem? I guess you might say "check the ping time and when the client gets the server projectile creation message it moves the projectile forwards as long as it would travel on the ping time, then it won''t hit the player''s back" (well, perhaps half the ping time would be more suitable). This would probably work well in some circumstances. However, what if there is something in-between the place where the projectile was fired and the place where we calculate that it should be when we get the server "projectile created" message? Then the projectile ought to hit this thing but we have to simulate the projectile trajectory between the origin of the projectile (position A) and the place it would be at when we get the server "projectile created" message (position B) in order to detect the collision. Worse, what if something is moving between A and B? Then we would have to simulate the movement of that thing as well, and this does really not seem to be feasible. Perhaps one could create the projectile at position A and disallowing it from hitting the player that created it? I would be thankful if someone could explain how to solve this for me very tricky problem, or come with some good ideas. Keen regards, Magnus
I like to write games.. and to do real sports.
I can see what you''re saying, but it''s just not possible unless you purposely delayed the creation of the projectile.

For instance, if the player is still able to move forward after firing that projectile, then the server is still receiving messages and broadcasting the new player position to the rest of the clients. Thus, if the server is still broadcasting, then there would be no delay for the projectile...

Basically, if the bullet won''t move because of message processing delays, then the player won''t move either, because they both send messages to the same server, which are processed one at a time as they are received. Since the bullet message was received first, the server needs to process that before the player can move. So unless the bullet''s creation time was set to activate 5 or so pings after the initial message, it wouldn''t hit the player in the back.

Are you really having this problem with a game you''re making, or are you just speculating?

If you''re really having that error, then your message processing needs some tweaking. Even with major lag, this shouldn''t be happening.

Let me know how it goes. Thanks.
Advertisement
quote:

Basically, if the bullet won''t move because of message processing delays, then the player won''t move either, because they both send messages to the same server, which are processed one at a time as they are received. Since the bullet message was received first, the server needs to process that before the player can move. So unless the bullet''s creation time was set to activate 5 or so pings after the initial message, it wouldn''t hit the player in the back.



There is a small note in my post telling "that the client has authorization about the client''s position (that is, the position that the human playing at the clients sees that his player has is always correct)." This means that the player can move even if messages to the server are delaed. Thus, the projectile can be delayed due to high ping, but the player is not delayed by high ping since the player moves independently of the server. So, if you know that the player can move even if the projectile is delayed, then you might also think that there is a chance that the player will get hit by a delayed projectile from behind?

( I think it is better to let the client has authorization about the client''s position since then the client player at least won''t experience lag when moving his own player. I have played a game (XPilot) on modem in which it seems as if the player position is updated after receiving messages from the server only (that is, the client has not authorization about the client player position) and it was completely impossible to control the spaceship since the motion of the spaceship was delayed too much after the actual input on the keyboard (if I remember correctly. However, on LAN the game was really OK :-).
)

quote:

Are you really having this problem with a game you''re making, or are you just speculating?



I am just speculating. It feels better to know how to do things before doing them, I think :-)


Thanks / Magnus
I like to write games.. and to do real sports.

This topic is closed to new replies.

Advertisement