0
\$\begingroup\$

I'm working on a multiplayer game and for bullets that players shoot I was wondering what is the right way to do it:

when a player press a key It send the key code to server and:
a. server starts moving the bullet and sends the bullet location to clients
b. server tells the clients to generate a bullet and move it in angle x, with speed of x for duration of x

well the second way makes more sense but I'm worried about players being able to cheat in the second way. So How should I do this without players being able to cheat?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

The bullet may not actually matter. The safest way to design such a system is giving full authority to the server. This means that only the server simulates critical events, such as damage or death.

The bullet and shooting effects may just be for show on the client. The downside of this is that it may produce some odd effects in laggy environments, but the end user shouldn't be playing a shooter in a laggy environment anyway.

It's also worth considering that the user will expect immediate feedback when they shoot a gun. So it makes sense for that client to create their own shooting and bullet effects. But everyone else's projectiles are created only on the server's instructions.

Client validates the conditions for shooting locally, and if they are fine it will create the bullet and play the shooting animation. At the same time it sends a request to the server, which then validates again. If everything is fine the server relays the shooting command to everyone. If anyone is subsequently damaged by the projectile, the server alone makes that decision and informs all of the clients of the outcome.

Keep in mind you'll need to integrate prediction for this sort of solution to be satisfying.

\$\endgroup\$
0
0
\$\begingroup\$

These options aren't mutually exclusive. Both the server and the clients can be simulating the bullet (that way it can continue to move correctly even if there's a delayed/dropped packet from the server).

The only question is which simulation has the final authority when we claim the bullet hit or missed someone.

To fairly adjudicate that, the server needs to simulate the bullet and report when it hits something. If the server says you got hit, everyone's simulation has to update to include the effects of that hit.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .