Search Unity

Pre-Solve event?

Discussion in 'Physics' started by lightbug14, Sep 1, 2020.

  1. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hello, I want to achieve some behaviour that depends on detecting the collision between two dynamic rigidbodies, but at the same time preventing the physics engine from solving it (based on some condition). Basically i'm looking for a "Pre-solve" event (from Box2D).

    I believe PhysX and Box2D already do this (probably not in the same way).

    PhysX (https://alanjfs.github.io/PhysX4Guide/Manual/AdvancedCollisionDetection.html#contact-modification):
    Contact modification:
    Under certain circumstances, it may be necessary to specialize contact behavior. For example to implement sticky contacts, give objects the appearance of floating or swimming inside each other, or making objects go through apparent holes in walls. A simple approach to achieve such effects is to let the user change the properties of contacts after they have been generated by collision detection, but before the contact solver.


    Box2D (https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_dynamics.html#autotoc_md109):
    Pre-Solve Event

    This is called after collision detection, but before collision resolution. This gives you a chance to disable the contact based on the current configuration. For example, you can implement a one-sided platform using this callback and calling b2Contact::SetEnabled(false). The contact will be re-enabled each time through collision processing, so you will need to disable the contact every time-step. The pre-solve event may be fired multiple times per time step per contact due to continuous collision detection.


    UnityPhysics (DOTS) also allows this by using the simulation phase 2 callback (https://docs.unity3d.com/Packages/com.unity.physics@0.4/manual/simulation_modification.html).

    So, Is this event hard to implement? (Unity side)
    There are things i can do to overcome this, for instance i can predict if a dynamic object is going to collide with a static object using physics queries. If it does, then i can ignore the collision. However, this is an unnecessary trick. An event to handle this type of situations would be great.


    Thanks in advance!
     
    Edy likes this.
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    @yant @MelvMay, sorry to bother you guys :oops:, i know you are really involved with all the Physics stuff in Unity (and probably are too busy right now with DOTS). I just wanted to know if events like these ones (pre-solve, post-solve ,etc) will be implemented in the future.

    Thanks.
     
  3. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
  4. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447