Search Unity

Deterministic collision without physic

Discussion in 'Scripting' started by mgrenier, Jul 23, 2011.

  1. mgrenier

    mgrenier

    Joined:
    Apr 26, 2011
    Posts:
    57
    I did my homework and found out that PhysX wasn't deterministic. I want to build a retro-style game wich always plays better with tight controls predictable responses.

    So my question is, is it possible to get rid of the physic and still get the collision event?

    My ultimate goal is to achieve tight controls deterministic collision (for replay networking purpose). So it doesn't matter if I need to write my own algorithm in the end.
     
  2. BotMo

    BotMo

    Joined:
    Mar 2, 2011
    Posts:
    101
    Yes, anything is possible, but collision code is a giant pain in the rear to implement.You'll have to read vertex positions, tangents, normals, and then see if any other object occupies that space at any given time. It would be no small task.

    If you want tight controls, just use different kinds of Force on your objects. For example, Instead of ApplyForce(myobject.position.forward) use ApplyForce(myobject.position.forward,Force.VelocityChange) This will make your object move wherever you tell it do regardless of physics, but it will still keep the collision. Theres 4 kinds of Force you can use. 2 use the object's mass, the others ignore it.

    If you want an object to move instantly and stop instantly, you can just make it's mass and friction really high, and apply a really high level of force to the object to move it, or dynamically change the object's mass/friction so it stops faster. I'm sure you can find a workaround fairly easily with some creativity rather than code your own collision system.

    Whether or not you can disable physics entirely and go with just kinematic, and still read collision data, I don't know. I would be interested to know if you find an answer.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes - what you are looking for is raycast.

    It will also give you the normals of the ray that was cast and you know your own movement code so you can "trace" with a co-routine that performs the action in the background. I did this with our old snooker game to predict what would happen.

    So two things:

    a) you can have a clone of the game world which you clone and update with coroutines to simulate what happens in the future (with a little lag as it catches up, you can disguise this with design)

    b) or you can raycast and roll your own collision response.
     
  4. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
    Just a conceptual question, how do you guys use the rigidbody physics in your games?

    A - Just use it for things, I don't need control over.
    (tin can that can be shoot and I don't really care where it flys)

    B - Also use it for things you want precise control over
    (player movement, how does animations function in this context?) (trial / error or equation based?)

    C - Don't use it at all.
    ( implemented my own Collision Detection/Response )

    Also please be a bit elaborate with your answers, so I get a better understanding when to use the physics engine.
    Because so far I don't really see how you use it without giving up all control or ending up having todo lots of trial/error.
    (I still have not found the equitations for the drag value for example, there is different ones posted tough but no confirmed one)

    Thanks your input is valued.
     
    Last edited: Jul 24, 2011
  5. mgrenier

    mgrenier

    Joined:
    Apr 26, 2011
    Posts:
    57
    I'm still experimenting testing different approaches. I did a quick test and ran different simulations with different techniques: http://labs.mgrenier.me/unity/Collider.html rigid bodies (no gravity, not kinetic, X/Z rotation constrained) that Translate into each other (no force, applyforce or vectors). This test illustrate that using rigid bodies, you get different outputs from the same initial setup.

    I'm off on vacation for a week. I'll play with @hippocoder's suggestion on raycast when I get a chance.
     
  6. skwaler

    skwaler

    Joined:
    Aug 12, 2011
    Posts:
    10
    Hi mgrenier

    Out of interest how did you get on with the raycast approach?

    sk
     
  7. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    6 years later unity still haven't any solution for deterministic physics, this is painfull, my project can't be done without it