Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved How to slow down depenetration of overlapping colliders?

Discussion in 'Physics for ECS' started by fataldevelop, Aug 30, 2023.

  1. fataldevelop

    fataldevelop

    Joined:
    Jul 5, 2014
    Posts:
    17
    Hi, i'm trying to figure out how to slow down depentration of overlapping colliders.
    In Unity PhysX there is a parameter MaxDepenetrationVelocity, but in Unity.Physics dynamic colliders just shoot out of overlapped collider.
    I was trying to manipulate PhysicsVelocity component, but all i can do with it is to slow down dynamic object after depenetration. It doesn't affect depenetration speed.

    UPDATE
    I've updated the demo with Daniel's suggestions, now the dynamic green sphere goes slowly out of static brick like in PhysX. You can take a look at ContactsSystem

     

    Attached Files:

    Last edited: Sep 3, 2023
  2. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    First off, have a look at the contact modification demo in the PhysicsSamples project.
    It shows various cases in which contacts are modified, including a "soft contacts" modification which could give you some good pointers of what values to modify and how.

    As a matter of fact, in your case you would need to modify the
    VelToReachCp
    quantity in the contact jacobian struct.
    See here:
    upload_2023-9-1_7-55-15.png

    As you can see, we do cap the velocity but we use a different internal default value than what you desire:
    3 for dynamic/dynamic pairs, and infinity for dynamic/static pairs (which would be the case in your example I suppose) instead of the desired 1.

    So, in your contact modification script you can just cap the velocity again with a different max depenetration velocity:
    Code (CSharp):
    1.  
    2. float maxDepenetrationVelocity = 1f;
    3. float solveVelocity = math.min(maxDepenetrationVelocity, jac.Angular.VelToReachCp);
    4.  
    5. jacAngular.VelToReachCp = solveVelocity;
    6.  
    That should do it.
    Let me know if that works.
     
    Last edited: Sep 1, 2023
    fataldevelop likes this.
  3. fataldevelop

    fataldevelop

    Joined:
    Jul 5, 2014
    Posts:
    17
    It works! :) Thank you very much, sir.
    Demo is updated
     
    Last edited: Sep 3, 2023
    daniel-holz likes this.
  4. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    Awesome! I'm happy to hear that.
     
    fataldevelop likes this.