Search Unity

Shoot position issue on Unity multiplayer

Discussion in 'Multiplayer' started by Warsoul, Oct 10, 2017.

  1. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    39
    I have some weird issues on the second player of my new unity game based on the Tank Multiplayer Asset from Unity Store. Anyone can help me to fix this issue ?



    The 1st player work has expected but the second(non-host) player shoot their bullets behind him when he move in the same direction he shoot.

    I tried :
    • Change the sendrate in Edit/Project Settings/Network
    • Change the sendrate in the Network Transform Script of the player
    • Change the sendrate in the Network Transform Script of the bullet
    I don't know what to do and i'm stuck here. Please help ! How we made an top down multiplayer game without this issue ?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't see any scripts to look at how you're doing it, and I'm not going to go through another tutorial to get the answer, but the bullets appear to be instantiated on the host at the position the 2nd player tank was when firing, but the tank has moved by the time they are spawned on the client. Time delay between when a client wants to do something and when it actually happens on the server and propagated across all clients is a common problem in networked games with a variety of solutions and workarounds.

    No matter how frequent you make the send rate it cannot eliminate the delay entirely, and it will be worse when a client is on another computer somewhere else on the Internet. You can't eliminate ping times by just sending updates more often, they still all have the same ping time.

    A few possible ways to deal with it:
    1) Instantiate the bullet immediately on the client firing instead of waiting for the host to spawn it back on the client - this will be tricky for a novice to pull off correctly, as you'll either want to sync it back up with a spawned bullet, or you'll want to just instantiate bullets on all clients and deal with slightly different physics outcomes of the bullets (on some clients it may appear to hit, while on the local client it may miss, etc, you'll have to deal with that)
    2) Slow the movement of tanks or require tanks to be stationary when firing so this issue will be less visible
    3) Make tank movement fully host authoritative, so a client presses a key and that runs a command that is run on the server to do the movement of the tank, which is then propagated back to the client - this will add a slight delay every time a client does any movement, but when bullets are fired they will be in sync with the tank's position on the client (they both will effectively have the same delay)
     
  3. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    39
    Thank you really appreciated.

    Which solution most multiplayer game chose ? 3 ? Game like dota or twisted metal use which technique ?

    Where i can find tutorial on the #3 solution ?
     
    Last edited: Oct 10, 2017
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It really depends. I couldn't say what those 2 games do either (I haven't played either one).

    In a game I'm developing I'm using #3, but I'm dealing with slow moving / slow turning wooden sailing ships firing cannons. Players don't notice delay when turning the ships because they are intended to be slow to turn. I know a lot of twitch FPS games would do some variant of #1. #2 would just be the easiest thing for a novice to implement.
     
  5. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    39


    What do you think they use ?
     
  6. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    39
    They seem to not have that issue at all.
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You can't tell this type of thing by watching a video. No idea.