Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Particle Based Deformations in UnityPhysics

Discussion in 'Physics for ECS' started by GHOSTBLACK, Mar 31, 2024.

  1. GHOSTBLACK

    GHOSTBLACK

    Joined:
    Apr 25, 2018
    Posts:
    13
    Hey guys, could you please tell me how to create a custom physics collider based on deformable points with spring connections and thus achieve SoftBody simulation? I'm not interested in fake simulation methods or using spheres and spring joints. My focus is on UnityPhysics and having full control over points and connections with CPU-based computation.
    My solution is based on Position-Based Dynamics (PBD) systems and utilizes a framework of point positions and connections with elasticity.







    A similar solution has been present in Bullet Physics for a long time, and here's how it's described:
     
    Last edited: Mar 31, 2024
  2. icauroboros

    icauroboros

    Joined:
    Apr 30, 2021
    Posts:
    177
  3. GHOSTBLACK

    GHOSTBLACK

    Joined:
    Apr 25, 2018
    Posts:
    13
    Thank you for the response, but I've already studied all this information. The question here is how to detect collisions and work with object collisions within Unity Physics. I don't want to create a primitive solution simulating the ground; I want to integrate with UnityPhysics and use something like TerrainCollider.

    The better question would probably be: How to build a physical body based on Unity Physics using points and connections.
     
  4. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    854
  5. GHOSTBLACK

    GHOSTBLACK

    Joined:
    Apr 25, 2018
    Posts:
    13
    My interest only in Unity Physics based in DOTS, with the ability for full customization and modification code.
     
  6. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    854
    In that case, this thread belongs in "Physics for ECS" where you'll probably get more focused replies than in general physics. You can report your thread for a moderator to move it.
     
  7. GHOSTBLACK

    GHOSTBLACK

    Joined:
    Apr 25, 2018
    Posts:
    13
    Thanks) I requested a transfer threads.

    I'll describe a bit more about what I'm talking about. I'm creating an array of points and connections, example a car chassis, and I need to build a deformable physical framework that could receive information about point deformation and its force, and then modify the physical framework shape based on the Position-Based Dynamics (PBD). I understand and know how to interact with points, as well as how to use the Position-Based Dynamics (PBD) formula. However, I don't understand how to interface with UnityPhysics collisions and creation custom colision data object.

    2024-03-31 15.18.29.jpg 2024-03-31 15.18.24.jpg 2024-03-31 15.18.16.jpg
     
  8. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    329
    For adding custom colliders you will indeed have to modify the source code at this point.
    I assume you will need to achieve two things here for an integration with Unity Physics:
    1. Detect collisions between your PBD models and Unity Physics' rigid bodies
    2. Couple the PBD simulation with Unity Physics rigid body dynamics simulation
    (2) can be achieved simply by incorporating extra contact constraints in the PBD solver, and by adding external forces based on the PBD position corrections for these contact constraints to the colliding rigid bodies after the PBD solve. For detail see this paper.
    As a prerequisite for this step, you will obviously need to achieve (1) in order to get the required collision intersection information.

    You can use two approaches for this:
    1. Without modifying the source code, simply add a kinematic rigid body with a Unity.Physics.BoxCollider to your simulation for each mesh-based PBD model you want to simulate. This box, which you will resize and reposition according to the axis-aligned bounding box (or optionally oriented bounding box if you want to get a tighter fit) of your deformed PBD mesh every frame, will allow you to get collision notifications (using the ITriggerEventsJob interface) for any Unity Physics rigid body in the simulation that could potentially (!) intersect with the corresponding PBD model. The detailed collisions with the potentially colliding rigid bodies you can calculate yourself with any mesh-based intersection algorithm. You can potential use some helper functions from Unity Physics for this. Implementing a simple naive version first which simply collides every potentially intersecting Unity Physics collider with all the triangles in your mesh without any spatial acceleration structure in place to find candidate triangles could be a start. You can use the Unity.Physics.PolygonCollider and it's collider cast functions for this.
    2. Heavily modify the source code of Unity Physics to get a deeper integration. This would be quite time consuming and tricky and would require a deep understanding of the lower level collision detection and physics world building code in the engine. So I would encourage you to go with the alternative approach above.