Search Unity

Multiplayer Game Hit/damage Approach And Should I Encode It?

Discussion in 'Multiplayer' started by rooskie, Apr 15, 2019.

  1. rooskie

    rooskie

    Joined:
    Jun 3, 2015
    Posts:
    20
    Hello!

    I'm working on a multiplayer game using Unity and socket.io. Most of the logic for spawning enemies, points and so on is pretty clear but I kinda just want to validate something with the community.

    It's a co-op type of game at first. The idea is that users can create new sessions (start new game) and let others join their session at any time. The user who created the session is becoming a host. The logic for spawning enemies, points, and progress is all server side. The host game instance runs all the enemies (animation, navmesh pathfining, colliders etc.) the other instances just display dummy enemies.

    Question:
    The host detects hits on bots using bot's collider and then reports it to the server. Is this a good approach? Is there any other, more efficient/secure approach?

    Another question:
    Should I encode this message (that a bot took damage) to the server? If so what's the common approach for that?

    Thank you!
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Server detects hit on collider, and inform a client.
     
  3. rooskie

    rooskie

    Joined:
    Jun 3, 2015
    Posts:
    20
    How would the server detect the hit on collider?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Just like any other authoritative server.
    By running simulation (running actual game environment) on the server.
    Trusting a client is never secure, if that matter to your.
     
  5. rooskie

    rooskie

    Joined:
    Jun 3, 2015
    Posts:
    20
    Do you know of any examples of how to do that with node.js? I can't seem to be able to find any.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    I remember reading in past that people used node.js, or C based server side authoritative environment for Unity. That may work. But if your game has physics involved, you want headless server side Unity application running. This will ensure that physics is as close similar, on both server and clients, which will require periodically syncing players.
     
    Joe-Censored likes this.
  7. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    In a co-op game I wouldn't think that an authoritative server is too important - unless you've got a leaderboard of sorts.
    If the client detects the hits you'll get instant feedback and the game will naturally feel smoother.

    In my opinion, if you're letting the client make game changing decisions, you should let all clients make decisions, otherwise this just means the "host" has a better experience than everyone else and is able to cheat.

    Say for example your host thinks a moving enemy is at x:1 z:1, his buddy sees the enemy at x:0 z:0 and tries to shoot it.
    The host will think his buddy missed, his buddy will think he hit and will be sadly disappointed. Then he'll need to start leading his shots based on his latency, which is never very consistent.

    Ever hear people complain that their shot "didn't register"? They're not always just being salty, this can happen when the client and authoritative server disagree on the hit.

    Sure you can implement client side prediction, but you'll never get that nice satisfying instant feedback of popping zombie brains with a well placed headshot.
     
    Joe-Censored likes this.
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    The leading of shots is solved with Lag Compensation. https://twotenpvp.github.io/lag-compensation-in-unity.html
     
    Antypodish likes this.
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Trust clients = be ready to accept cheats.
     
    Joe-Censored likes this.