Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Projectiles with Client Prediction

Discussion in 'Netcode for GameObjects' started by LazyDog_Rich, May 15, 2023.

  1. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
    Hi all!

    I am making a game that uses netcode + relay. And I've implemented client prediciton and server reconciliation, and everything seems to works fine on movement.

    Now I am trying to implement projectiles, and the problem I am facing is, if server aims and hit the client, the client will lose life. But from the client point of view, he wasn't hit at all, because is a bit ahead.

    What would be the best approach for projectiles along client prediction?

    I have this small test set up. If you are the server you are seeing the "real" positions of everyone. If you are a client you are using client prediction, and there's a gray shadow of yourself that shows you were you are acording to the server:
    https://rich4444.github.io/onlinetest2/
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,108
    You also need to implement server-side rollback to simulate a client event at the time the client issued the event, with all the game state rolled back to the client's timestamp. Basically you want to determine whether a shot was a hit at some time in the past with the simulation state at that point in time.

    Fish-Net has this implemented if I remember correctly, you may want to look through the codebase to get an understanding how this works. For Netcode it's on the Roadmap.
     
  3. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
    I already have server reconciliation, when there's a mismatch, I rollback the client to the mismatch momento, fix it, and replay all the inputs. Is that what you mean?

    What is fish-net? Could you provide me some link to take a look? Sorry I am so lost, this is my first attemp at doind a multiplayer game
     
  4. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    50
    LazyDog_Rich,

    If I understand your dilemma, you have client prediction with owner/client authoritative NetworkTransforms but you have server authoritative projectiles that visually seem to be out of sync on the client side relative to the client's player object and thus when a server detects a hit, for the client being hit, the visual of the projectile does not look accurate (i.e. doesn't look like the client's player was hit)?

    I have two possible ways to help with the visual alignment issue, but first want to confirm that this is the issue you are having.
     
  5. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
    Yes that's exactly the problem I'm facing! I have been trying different approach but nothing seems to work :(
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,108
  7. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
    Oh I see, I'll take a look at it thanks! But I hope @NoelStephens_Unity can give me some help so I can make it work with netcode!