Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics Lockstep w/ Networked Inputs

Discussion in 'Scripting' started by JoeOfTex, Oct 20, 2014.

  1. JoeOfTex

    JoeOfTex

    Joined:
    Dec 23, 2013
    Posts:
    10
    Hello,

    I'm trying to send all inputs over the network to other players to recreate the simulation on each client.

    The Setup
    I'm using Photon Networking with a send rate of 25.

    I have moved all of my movement and input functions to run off of one FixedUpdate function, and use Time.fixedDeltaTime to sync across devices.

    The Physics loop is set to 50 fps, so I'm sending 50 input states over the network every second, to cover every frame.

    The Draw loop is vertical synced to 60 fps.

    The Problem
    I'm packing multiple input states into one packet, since SendRate is 25, and Physics FPS is 50, this allows me to process input for every physics frame, but this scales automatically depending on SendRate. I record every input state, and pack all states that have not been sent into one packet.

    However, the game randomly runs out of inputs to process. This may be due to the OnPhotonSerializeView function running on the Draw Loop, while the inputs are simulated on the Physics Loop.


    Has anyone done anything similar? My game requires an accurate simulation on other clients, with delay being negligible, but would be nice to keep it lower than the average interpolation time of 100 ms.