Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Discussion Which Multiplayer Solution for Fast Paced Shooters?

Discussion in 'Multiplayer' started by Juice-Tin, Nov 27, 2022.

  1. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Hello, I've have a fast paced side-scrolling shooter that I am now trying to make online multiplayer.

    I've tried Netcode for GameObjects which seems great, however clients can't spawn Objects, and require the server to spawn for them.

    The problem is that is a player has 100ms latency, shooting the weapon while moving causes bullets to spawn 100ms delayed, and behind the player, this looks and feels VERY bad.

    So my question:
    1. Which multiplayer solution handles this issue the best?
    2. OR, if this is a common problem everywhere, is there a solution? Like maybe let the player shoot locally, but then the server creates a visual-only bullet to where the player shot to simulate it syncing?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    The authoritative model is still the best for this kind of game.
    The shooting player should locally predict that the bullet gets created or that the shot happens. Usually, the server will confirm this and maybe there is a minimal correction necessary. In rare cases, when the server disagrees, then the local prediction was wrong and needs to be cleaned up. This may cause glitches but some can be hidden and in general the server is right and it's best that all agree.
     
    CodeSmile likes this.
  3. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    I agree spawning locally. Server should handle damage and players just show visuals.

    Far as solutions go, Fish-Networking has a tick aligned simulation which makes this easy to accomplish. I actually am using the exact described behavior on a paid project with FishNet. https://fish-networking.gitbook.io/docs/ (links and more).

    I'm going to probably add a guide to this in the docs over the next few days; there's already a placeholder for it. https://fish-networking.gitbook.io/docs/manual/guides/lag-compensation/projectiles
     
    CodeSmile likes this.
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
  5. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Thanks for the info, looks like Fish-Net has the most features, though while using NGO so far I can definitely say it's quite easy to get going without much hassel.
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hey @Juice-Tin , FYI NGO is not recommended for competitive fast-paced shooters, as it's missing some much needed features such as prediction + reconciliation and rollback. It also doesn't scale well with large amounts of network objects (even though this really depends on what data you send about these objects).

    NGO is more recommended for games of up to 10 players per session/low amount of networked objects (think of Overcooked, Among Us, Hearthstone) where client-side prediction and reconciliation are not really needed (unless you're willing to implement them yourself)
     
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    I applaud such an honest statement! :)

    For future readers: prediction & reconcile is on the roadmap (currently "planned").

    I tried NGO, Mirror and Fish-Net recently and have to say, as far as getting started and ease of use is concerned, they're all on equal terms. ;)
     
    RikuTheFuffs-U likes this.
  8. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Thanks, @CodeSmile ! From my point of view, we're here to help. Picking the right framework from the beginning is important, as it is a decision that has an incredible impact over the project in the long-term.

    As a Unity user myself, working on multiplayer games, I'd hate if somebody gave me bad advice just to push a product of their company.

    Making multiplayer games is hard enough on its own already!
     
  9. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Thanks, I appreciate the honesty as well. 10 people max sounds fine, however there are TONS of bullet objects are very fast paced movements happening each frame, so it's definitely something to consider.

    With my 0 networking experience, I had a working online demo with join codes & server list in my existing game in just 2 days thanks to unity Relay & Lobbies taking care of all the server side stuff.

    I hear Mirror/Fishnet/Photon/etc requires your own servers & server code to connect with, which again, 0 experience. (Also on a VERY tight deadline for this, 2-3 weeks max)

    Does Fish-net have any simple Relay/Lobby system that automatically handles all the server-side stuff? Every tutorial I've seen only shows how to connect 2 clients locally.
     
    Last edited: Nov 30, 2022
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah. I think since Unity bought Rival recently for DOTS, and that contains a twitch shooter sample, it might be worth a look for projects starting out now. What do you think?
     
  11. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @Juice-Tin Do they really need to be networked, though? More often than not, you can get away with raycasting on the server and notifying clients about being hit.

    @hippocoder I'm not an expert of Netcode for Entities ("""the DOTS version of NGO""") or DOTS in geenral, so I'm not sure of what the consequence of that purchase will be... Something seems to be moving, though!
     
  12. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    @RikuTheFuffs-U Sort of, here's a clip of a 6v6 with AI bots using rockets, physics-based grenades, ragdoll physics (which are important, as dead bodies also block bullets)
    https://i.gyazo.com/bc2f5f4f2f31667fcf019c3c32ec0f6e.mp4

    My concern now is because it's so fast paced, even a small delay in: "client shoot > server authenticate > tell client" could feel like an eternity, which may be exaggerated based on the amount of networked game(and physics)objects required.

    Happy to try out Fish or Photon, just can't figure out if their online setup is as easy as NGO Lobbies/Relays was. Can't find much info on it.
     
    Last edited: Nov 30, 2022
  13. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    I wanted to let you know that I finished the guide today. The code examples naturally are for my networking solution but I'm sure it could be converted to anything. There's a preview of the outcome as well so you can see the results before diving into the code.

    If the page still says 'coming soon' you may need to refresh it.
    https://fish-networking.gitbook.io/docs/manual/guides/lag-compensation/projectiles

    EDIT: here's the preview with a large ping of 220ms.
    PredictedProjectile_00.gif
     
    Last edited: Nov 30, 2022
  14. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I just checked out your video. Looks nice.
    You've been open to using Photon solutions, so I think it's OK to add some details.

    If it wasn't "finished" already, I'd say it's a perfect fit for Quantum. It is deterministic with predicted movement and can do a few nice tricks. E.g. you could actually implement jumping on (or just over) a flying rocket. See the Quantum Demo "Blueless". There is also a Bot SDK, which helps populating multiplayer games.
    It works especially well for mobile games, as our servers coordinate the input and no host / server is needed on top. This also means, it does not matter if any player gets a call or closes the app - the game continues for the others.
    But .. your game is basically done. It will be quite some work to convert.

    Fusion would be a good fit for shooters in general. Downside: In our experience, it's not great to run a host on a mobile client. It will be interrupted frequently during gameplay and this affects everyone. This will be the same for other solutions which use a Host/Server. Fusion helps you get Host Migration done but this technically never works without interruption.
    The "shared mode" for Fusion is better for mobile (it doesn't rely on a single host/server) but less good for fast paced games and there are likely more corrections. Check out the samples for Fusion. Reconciliation is explained here.

    Unless you'd refactor the game a lot (to ECS / Quantum), you will likely end up with a client hosting the game. This has some drawbacks, no matter the solution you pick.

    Happy coding :)
     
  15. TRVGod

    TRVGod

    Joined:
    Feb 20, 2022
    Posts:
    2
    And if we implement own client side prediction systems?
     
  16. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    You may as well write your own networking solution at that point. Implementing CSP on-top of another framework that isn't built for it will be annoying at best.

    CSP isn't easy to get right, and if you plan on using rigidbodies it just became 20x harder. If you need CSP use a solution that already has it like...
    FishNet: https://assetstore.unity.com/packages/tools/network/fish-net-networking-evolved-207815
    Fusion: https://www.photonengine.com/fusion
     
  17. genxium

    genxium

    Joined:
    Jun 7, 2013
    Posts:
    16
    If you're just concerned about syncing positions in "real-time", it's often fine to just send positions of "self-controlled character" @30fps (example of a relatively fast rate) as well as a few critical events like shooting asap.

    Having 100ms or even 200ms delay (assuming single trip) between players is inevitable, and the worse situation is having a nonuniform delay pattern like [16ms, 200ms, 13ms, 500ms, ...], as a developer we need design proper input/skill delay & predictions to compensate for such inevitable edge cases. Some annoying cases are worth mentioning.
    - Shooted bullet or jumped other players' positions always teleported a few frames after invocation (input delay + skill startup frames can help mitigate)
    - Other players' turning around motion (any kind of inertia implementation can help mitigate, either using acceleration or not)
    - Propagating momentum by chained collisions

    However there are more to be concerned before you decide your netcode.
    - Do you need many npcs in any level?
    - Do you need recording of battles to be replayed, if yes do you need the history at a given frame id be the same for all players?
    - Do you have a tight budget for bandwidth of the netcode packets? A smaller bandwidth requirement often results in higher success rate of transmission.

    Putting all these into consideration, I'd recommend implementing a rollback netcode for your own game mechanics, it'd take sometime to get things right especially the "rollbackable physics". Unity seems to have a documentation about its own https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/physics.html but it's usually a bad idea to just take a general purpose physics engine into a specific rollback game, because of performance concerns for the wasted time in calculating all the stuff you don't need.

    To make sure that I am not just talking bullsh*t, here's my pet project using rollback netcode https://forum.unity.com/threads/sha...-with-some-success-in-internet-tests.1426356/ and by far it works great in internet tests -- it's server-authoritative but not required to run game simulation on server. You might also be interested in some edge cases' concerns here https://github.com/genxium/DelayNoMore/blob/main/ConcerningEdgeCases.md.
     
    Last edited: Dec 11, 2023