Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Host vs client, who should fire the bullet?

Discussion in 'Netcode for GameObjects' started by splundge, Mar 25, 2024.

  1. splundge

    splundge

    Joined:
    Dec 29, 2021
    Posts:
    24
    As the title suggests...whats the best approach to firing projectiles in a multiplayer game?

    I was thinking
    - all clients can fire a projectile. Calling this rpc will trigger on everyone's game
    - the projectile will impact and explode on every client, but only the host will calculate the damage, and send it back out to all clients
    - all clients can fire hitscan weapons, but the host again, will determine if the hitscan hit th target

    Is this the right approach? Is there another?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Sounds about right. Reminds me that I still have to implement client-side projectiles, for the time being I just spawn them server side which works pretty well even with simulator set to create a 100ms RTT..

    One thing to keep in mind: when the server projectile impacts, clients need to destroy their versions too because it may have missed. And vice versa: client side impact, but server side miss. That‘s why I went for the less complicated implementation for now. Probably best to not let client projectiles impact on client side to avoid this complication.
     
    splundge likes this.
  3. splundge

    splundge

    Joined:
    Dec 29, 2021
    Posts:
    24
    aah yep good point on client projectile potentially missing! might be best to tell the server to explode it. (thing is, the projectile is NOT a network object. maybe it should be for this reason)