Search Unity

Lockstep deterministic collisions

Discussion in 'Multiplayer' started by Alvarus, Mar 22, 2013.

  1. Alvarus

    Alvarus

    Joined:
    Apr 10, 2009
    Posts:
    203
    We're making an RTS based on the lockstep model. Movement was 100% accurate across the network until we added collisions using kinematic rigidbodies with is trigger compound colliders, now we lose sync. The Unity docs state that:

    Is Kinematic: If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform.


    Does the Is Kinematic setting actually disable the physics engine, rendering the colliders usable for deterministic simulation?

    If kinematic colliders are useless in this case, are there any suggestions on the best way to detect and deal with collisions in lockstep?
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    If you need deterministic collision detection this is something you will have to implement yourself, by hand - you can in now way use unitys PhysX engine for this. So yes the default Unity rigidbodies are next to useless for this.
     
  3. Alvarus

    Alvarus

    Joined:
    Apr 10, 2009
    Posts:
    203
    That's...frustrating. All we want is the collision data from the triggers, but as I mentioned, the data doesn't seem to be guaranteed to be the same on two networked computers given the same starting conditions once collisions start in earnest. I keep crossing my fingers in the hopes that someone will tell me that I forgot to click an obscure checkbox on the colliders and everything will work. But failing that...

    We've implemented a sort and sweep test, and so far it's quite a bit slower. Which isn't surprising, because it's not running on the GPU. Other people must have had this problem as well. What do other lockstep (Unity) RTS games use for collision detection? So far I've looked into a few options: sort and sweep, quadtree, trying to integrate Bullet Physics...
     
  4. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I have found that using a simple quad tree is very well suited for a lot of game types, despite it's inherent 2D nature. As unless you're in space or doing a flight-sime you are most likely going to move mostly on the X/Z plane and very seldom on the Y axis. If you base your positions on integers (which you should anyway, since you need deterministic behaviour) you can get a very very fast quad tree.

    Here is an example of a simple collision detector that uses a quad-tree to do overlap tests on 8000 AABBs: http://www.youtube.com/watch?v=Ds8ky2yjTs0&list=UU19DRfosULMdAbwh4IDpswQ&index=4 (I know the video starts lagging after a while, it has nothing to do with the algorithm - it runs at 60fps easily).

    Just FYI: The PhysX that Unity uses doesn't run on the GPU either.
     
  5. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
  6. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Axiom is a 3d/game engine for C#...
     
  7. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    Yes, with source code, that has a very nice math library