Rendering bullet tracers with spread: Client or server?

Greetings. I have been trying to code a gun as exercise, however I have come across quite the dilemma.

I am trying to render bullet tracers with spread. My first attempt was to render this on the server, which caused the client to see the tracers lag behind due to ping. Then, I tried to move the rendering to the client, which worked fine until I had to calculate spread. I could calculate where the bullet hit on the client, but I am terrified that the client could be malicious and send a far-away position, for example on another player, which basically allows exploiters to shoot through walls.

In more detail:

  • The tracer has to link the gun’s tip to where the bullet actually hit. (If the target was a mile away and behind a wall, the tracer must not extend past the wall)
  • Latency should be minimised, or preferably nonexistent.

I hope that what I am trying to achieve isn’t a perfectionist’s dream. Any suggestions on how to do it?

1 Like

Trust but verify, if the velocity is high enough, then consider using raycasting on the server without rendering them. This will allow the players to have a smooth experience but the server will verify all hit detection.

Otherwise, you could make hit detection a collective decision. Make all client’s report all hits. If only one person says it was a hit, then it most likely wasn’t. If everyone says it was a hit, then it most likely was one. Latency will of course mess this up slightly, so settling for a majority or something could work as well.

2 Likes

Question:
Given client A, B and the server, if I render the tracers…

  • On the server, then client B can also see the tracers, but client A will see the tracers with latency.
  • On client A, then only client A can see the tracers.
  • On both the server and client A, then everyone can see the tracers, but client A will see duplicate tracers.
  • Nowhere, then obviously nobody can see them, which is undesirable.

So where do I render the tracers?

Whenever the server notices someone firing it should fire all clients and notify them of this. All clients will then render the tracers themselves, while the server doesn’t. In this system, the following would happen:

1) A presses “shoot”. A will notify the server of this and promptly render their own tracer.
2) The server receives the “shoot” event and fires all clients with necessary information.
3) A & B receives the fired event, A sees that the projectile is shot by them and therefore knows it is already rendered, meaning it ignores it. B on the other hand has not rendered it, and will render it.

For extra accuracy you could include information such as time it was fired and account for that when creating the tracer

3 Likes

I’ll implement it and see if it works. By the way, where do you learn all this stuff?

Mostly self taught. I’ve done a lot of minor and major projects which have shown me pros and cons with a lot of stuff.

Answering stuff on the devforum is also helpful, although not to the same extent as simply trying things myself. By answering a lot of questions here I also get exposed to other peoples answers, which sometimes teach me something new.