Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Synchronize Unity physics and PhysX on serverside

Discussion in 'Physics' started by CyberSlime, Jan 31, 2018.

  1. CyberSlime


    Jun 24, 2015
    We are working on an MMO game which uses unity physics simulate player moves on the client, and the server run the same simulation use PhysX to authorize clients moves.
    The client-side moves are predictions. When the client receives the authorized position from the server, it will compare the sever position with the buffered position when the client sent the move command to the server, if the distance of two positions is too big, the client will make a correction.

    Because the PhysX is not determinism, those two positions never equal, but hopefully the difference will be fairly small.

    When the player runs on a flat ground, the difference is small enough and stable(about 1e-8), but when the player moves toward a wall, the player will slide along the wall, then the difference of the two positions become larger and accumulates.

    We use CharacterController.Move(Vector3 motion) in unity, and on server we use

    virtual PxControllerCollisionFlags PxController::move ( const PxVec3 & disp,
    PxF32 minDist,
    PxF32 elapsedTime,
    const PxControllerFilters & filters,
    const PxObstacleContext * obstacles = NULL

    I think the minDist in PhysX's move function which unity does not expose may cause this difference. What's the value unity use in this function?

    And the collider in PhysX has a restOffset property, unity doesn't have this too, what's this value unity use?

    Finally, we use Unity 2017.2, is the PhysX's version 3.3.3?
  2. zhuchun


    Aug 11, 2012
    Hi, 10 months later and I see this post. Unity has done lots of effort to make PhysX ease to use, that's really good. On the other hand, I would call it "Unity PhysX" but not "Nvidia PhysX", there's too much black box inside now. So I met the same problem and turned to another physics engine instead, no deal for me until Unity opensource their solution. It takes time, I don't bitch ;), "Unity PhysX" is an excellent choice though.
  3. labandunga


    Aug 1, 2012
    What engine did you decide to go with? Bullet? How are the performance / Interpolation results?
    Would appreciate it if you can share your insight as I'm going through a similar choice right now.
  4. zhuchun


    Aug 11, 2012
    @labandunga It's hard to make a fair performance benchmark for PhysX and Bullet, since the target device and usage may vary from project to project. Regarding interpolation, it's more about networking strategy so it shouldn't be a problem. You can spend some time(less than a week) to read the code of Bullet v2, it's easy to understand.

    Bullet is a good starting point for people who want to open the black box of a 3D physics engine. You can get the full power of a physics engine and do almost anything you like, say networking or make some fancy physics solvers. However, please avoid this if your project/team require you to showcase something soon, it's time-consuming in fact.