Search Unity

Question about StateHistory Misses

Discussion in 'FPS.Sample Game' started by Enzi, Oct 30, 2018.

  1. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    258
    Hello!

    I've implemented the movement piece-by-piece in a new project. Works fine were it not for constant missed predictions.
    As most is now copied files I'm not sure how to progress so any hint in debugging this? No problems in the FPSSample with it.

    What happens?
    I press forward for a little while and when released the client character continues moving without stopping. (movement is correct on the server or at least it seems)
    It doesn't stop because the velocity gets calculated wrong in Movement_HandleCollision.
    The Movement_HandleCollision is wrong when the moveQueryStart is set from characterPredictedState.State.position after a Deserialize of CharacterPredictedState.
    They are wrong because the predictedState was a miss.

    Misses are in the range of 0.5 length and it's too high for Lan connection.

    So how can I prevent this and where is this happening usually?
    I've not implemented Animations. Is this crucial for this?

    Thanks for any help!
     
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    258
    Oh boy, I had to enable "Auto Sync Transforms".
    That took me longer than I anticipated, I thought it was a code bug but when I realized that the CharControllers position is not reset correctly in the rollback, it clicked.

    At least I learned a lot from the code. Very nicely done!
     
  3. Mogens_H

    Mogens_H

    Unity Technologies

    Joined:
    Mar 7, 2017
    Posts:
    20
    Are you talking about Physics.autoSyncTransforms ? That should not be neccessary as we dont use physics simulation in movement (we only use simulation for some client side shatter).

    I dont know what your issue is, but there are some gotyas regarding movement:
    - gameobject.transform is not called in movement code. Only state pos+rot is updated (transform is updated later)
    - CharacterCollision is a seperate object that is moved to do the collision queries
    - Rollback will always snap back to last server position, but new position is calculated "op top" of this every frame
     
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    258
    Yes, Physics.autoSyncTransforms. But it's only needed on the client side!

    I just tested it in the original FPSSample. Turned it off on client and I had the same wrong behaviour. Client char walking in a direction.
    There's no call to Physics.SyncTransforms in the code that would prevent this.
     
  5. Mogens_H

    Mogens_H

    Unity Technologies

    Joined:
    Mar 7, 2017
    Posts:
    20
    I see. Must admit that I never looked into this property before you mentioned it. But yes, we have it set to true in our projectc settings,
     
unityunity