Determining which player scored against another player in a multiplayer game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ertain

I have a multiplayer game, and I need to determine who scored points and kill counts against other players. I’m mostly using projectile weapons in the game, so raytraces are rarely used, and the weapons shoot individual bullets towards other players.

Currently, the bullets carry the shooter’s name, and so, on collision with opponents, the player script checks the name on the bullet. On a successful kill, the killed player’s character script emits a signal that they have died, and passes the name of the previous player who shot them. This is complex, and I would like to simplify it.

:bust_in_silhouette: Reply From: Wakatta

Firstly when dealing with multiplayer or just any game in general one should have the code deal with all the interactions and the art/effects/visuals represent those changes. So mixing the two is a big debugging nightmare waiting to happen.

Keeping that in mind you’d want to have these functions in a singleton or your main scene

send_encoded_packet() #sends data between clients or to server
receive_encoded_packet() #what to do when data is received

  • verify_data_received()
  • sync_local_data_with_received_data()
  • update_visuals_to_represent_received_data()

if your connections are p2p have a Host randomly assigned that receives all the data
quality checks it then sends to all connected clients

if you want actual code snippets that’ll depend on the type of game you’re developing

If you’re wondering what kind of game it is, the game is a 3D shooter.

Ertain | 2021-01-18 08:45