Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug NetworkTransforms are hovering on non-Owner machines

Discussion in 'Netcode for GameObjects' started by mechturtle, Jul 21, 2023.

  1. mechturtle

    mechturtle

    Joined:
    Feb 3, 2018
    Posts:
    3
    I'm having an issue with the ClientNetworkTransforms on the players in my game. When jumping forward, the player will land on the ground properly on the owner's machine, but will frequently land in the air on the non-owner machine.

    I can get the transforms to sync up properly again by jumping in place, but if I jump while moving forward they immediately begin hovering out of sync again.

    upload_2023-7-21_15-39-42.png

    I've tried two different types of player controllers. One is a custom made solution that uses Unity's built in CharacterController, and the other is a simple RigidBody character controller purchased off of the asset store. Both controllers have the same vertical sync issue. The controllers' scripts are only ever enabled on the player owned by the client.

    The only NetworkBehavior script on the player is only responsible for health and nothing else. This happens on any non-owner instance of the game, both hosts and clients. The only axis that ever seems to get out of sync is Y.

    upload_2023-7-21_15-28-51.png
    A NetworkRigidbody was also used with the Rigidbody character controller

    Any idea what's going on here? Thanks for lookin!
     

    Attached Files:

  2. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Also had the same issue and read forum posts from people having the same issues. I solved the issue personally by turning interpolation off and back on after being airborne for more than a second, which will cause the player to snap to their actual location on all other clients.

    Basically any time the character controller reports not being grounded in a fixed update, I'll then start counting the time it has not being grounded for in fixed updates. The next time the transform is grounded, I will check the duration it wasn't grounded for. If it's more than something like 1 sec, I'll turn interpolation off until the next fixed update. This effect is rarely noticeable from other clients and would probably just be passed off as normal "lag shenanigans" by players in general. The same effect can probably be achieved by teleporting the network object to its current location on the client.

    Not ideal but if there's a better solution, I'm all ears.

    edit: this is a known bug that has been fixed in development: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2595
     
    Last edited: Jul 27, 2023