Particle Based Deformations in UnityPhysics

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:

You need to write it from zero and you have the hints already.

https://blog.mmacklin.com/publications/
https://matthias-research.github.io/pages/publications/publications.html

Or you can buy Obi from asset store.
LatiosFramework have a softbody goal I believe, but I do not know the current state.

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.

When you say “Unity Physics” are you referring to the PhysX 3D physics integration in Unity or Unity Physics?

My interest only in Unity Physics based in DOTS, with the ability for full customization and modification code.

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.

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.

9740797--1393492--2024-03-31 15.18.29.jpg 9740797--1393495--2024-03-31 15.18.24.jpg 9740797--1393498--2024-03-31 15.18.16.jpg

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:

  • Detect collisions between your PBD models and Unity Physics’ rigid bodies
  • 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:

  • 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.
  • 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.

Hello @GHOSTBLACK, did you manage to find a solution for this? I’m also looking for a way to implement soft body physics for vehicles deformation.
I contacted the author of Obi Softbody asset but unfortunately it seems that its not suitable for such things. He suggested to use a lattice asset (Lattice Modifier for Unity | Animation Tools | Unity Asset Store) but you have to implement collisions and anything related by yourself.
I was also thinking about an approach based on spheres and spring joints, why do you think that its a “fake” approach?

Hello Michele, I have a progress soft body deformation physics, write me PM and I will tell you about my experience.

1 Like