Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Synchronizing Animation Rigging Values Over Netcode Multiplayer

Discussion in 'Netcode for GameObjects' started by codeBatt, Apr 9, 2023.

  1. codeBatt

    codeBatt

    Joined:
    Feb 12, 2020
    Posts:
    40
    Hello, I can be said as a newbie in game development. I am making a third person shooter game using netcode for gameobjects. My characters using animation rigging to aim, shoot and other animations etc. However, a client and a host does not see each other in a synchronized way. I tried to make their values set by hand using server & client RPCs to make sure that, all of them are synchronized. But still they are not synchronized. What shall I do, this is also my first multiplayer game I am open to every possible advice.

    A code sample for my setting rig values:


    I am calling this method, using a server and a client rpc to make sure that all players' rig values are synchronized with respect to current animation. However, they are still see each other in odd rotations & poses.
     
  2. KyberCrystals

    KyberCrystals

    Joined:
    Sep 28, 2021
    Posts:
    2
    Hello, did you find a solution to this problem? I have the exact same issue.
     
    codeBatt likes this.
  3. codeBatt

    codeBatt

    Joined:
    Feb 12, 2020
    Posts:
    40
    This video will definetly be helpful, check it out
     
  4. Nyphur

    Nyphur

    Joined:
    Jan 29, 2016
    Posts:
    98
    They never will. You don't actually want to sync animation and bone positions across the network because then there'll be horrible delays on everything. Movement and animation need to feel sharp and responsive so they are done client-side instantly and then propagated to the server and other clients, but nobody else will see the movement and animation exactly as they are on the person who did it.

    The trick to putting a gun in the player's hand and syncing the position up for all observers is that each observer needs to be allowed to move it itself. You don't actually use any networking for syncing the position and animation of the gun, the netcode only handles telling the clients that player X equipped/unequipped the gun and then each player prefab needs a script that handles putting the equipped gun in the hand. Not a networkbehaviour, a regular old monobehaviour. Basically take all the networking out of the actual position and animation of the gun.

    If you need to have the animations synced because you're using the position of the gun to do shooting, you'll have to fake it. The client who shoots the gun is the only person who accurately knows what way it's supposed to be pointing, so they have to send that info to the server when the gun is fired and then everyone gets told a bullet is fired from the gun toward target y. This opens the game up to exploits because the client is in charge of bullet trajectories, but there's no other option that feels good to play.
     
    MrsMark, RikuTheFuffs and codeBatt like this.