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

Question Help with network flow for a tank game

Discussion in 'Multiplayer' started by hvtanh07, Jul 7, 2022.

  1. hvtanh07

    hvtanh07

    Joined:
    Nov 14, 2020
    Posts:
    8
    I'm new to unity network and currently building a multiplayer tank game.
    I'm using photon to control the network and a personal server, Right now when a player shoots a bullet and hit a clone it will send that hit reg to the server and the player who got hit will receive damage.
    However, if the shooter is lagging and shoots a clone that is moving slower than the real one then the hit will still be registered, which is unfair
    So I'm wondering is there a standard way to handle this like in other games where if you are lagging and you shoot a static clone the hit will not register?
     
  2. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    It's been awhile since I've used Photon but I think the following could still apply.

    Look for some sort of time that's synchronized between players (not sure if PUN has this). When firing send the time as well. Other players teleport the projectile expected move distance between current and sent time.

    Now the projectile is in the same position on shooter and other clients.

    You can rapidly accelerate the projectile instead of teleporting for a better looking simulation.
     
    Last edited: Jul 8, 2022
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    You should take a look at Photon Fusion, it has much better built in handling for exactly the sort of problem you describe.
     
  4. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    Are you sure? I don't remember seeing this as a feature, can you link me it please.
     
  5. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    In hosted mode, Fusion supports lag compensated hit boxes to account for the fact that each client sees other clients in the past and regular ray cast on the server would not match what the player was seeing. Lag compensation effectively allow the server to see the world from the players perspective at the time a given input was received.

    https://doc.photonengine.com/en-us/fusion/current/getting-started/fusion-intro

    Unless I've misunderstood the OP's concerns, this should help overcome the problem he is having.
     
    Last edited: Jul 9, 2022
  6. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    Ah perhaps. I saw projectile and assumed they meant something that moved over time rather than a raycast. I'm just going to put it out there that my free solution Fish-Networking has these features as well. But as someone that started on PUN way back I don't usually like to recommend a server auth solution out the gate unless they're serious about the project.

    Should OP want server auth I'd recommend Fusion if they're just developing for fun, FishNet if they're more serious about costs and growth. I make this recommendation off the facts that Fusion has a great free tier or even low-use paid tier. It's arguably easier to get grouped with friends for beginners as well. But beyond that the price tag is hard to see past. While the CCU limitations aren't so bad the bandwidth, messages per room, players per room and more do not scale well in costs.