Collisions are a quite important topic: most of the time, you will want your Obi actors (cloth, ropes, fluid emitters, softbodies, etc) to be able to collide against / react to other objects in your scene. Particles in an actor can also collide with each other, so Obi distinguises between two types of collisions with their own set of independently controllable parameters each:
Obi's collision pipeline is identical for both types of collision, and it's composed of 3 distinct phases:
Enabling collision constraints in the ObiSolver component allows particles to collide against ObiColliders.
Amount of iterations spent enforcing contacts against colliders during each substep.
Maximum velocity (in meters/second) applied to particles to take them out of a collider. This only applies to particles that start the physics step already inside a collider. Low values will gently take the particle out of the collider. High values allow the solver to take the particle out immediately, causing it to "jump" out of colliders.
Percentage of rigidbody velocity used to expand particles' bounding boxes during collision detection against colliders. A value of 1 will use 100% of the velocity, resulting in full continuous collision detection. A value of 0 will result in purely static collision detection.
Margin added to particle bounding boxes when generating contacts against colliders. Any colliders within the particle's bounding box will be considered for contact generation. This value should be kept relatively low. Large values will generate more contacts, which can improve robustness in very complex scenes, but will negatively affect performance.
Amount of iterations spent refining surface collisions against colliders.
Add an ObiCollider component to any collider in your scene to make it collide against Obi particles. You can add this component to SphereColliders, MeshColliders, BoxColliders... pretty much all standard Unity colliders, both 3D and 2D. The only collider types not currently supported by Obi are PolygonCollider2D and TilemapCollider2D. At the beginning of each simulation step, solvers will generate collision constraints for all their particles based on what colliders are spatially close to them.
This is how the ObiCollider component inspector looks like:
Sometimes you need a collider to be ignored by specific actors - or even specific particles: you can use categories and masks for this.
Each collider/particle can be in one of up to 16 collision categories, from 0 to 15. The "Collides with" mask determine which categories a collider or particle is allowed to collide with. It's possible for a mask to allow collisions with more than one category, or with all of them.
For instance: a particle in category 5 with a mask that allows collision with categories 8 and 10 would collide against any particle or collider in categories 8 and 10 whose mask also allows collisions with category 5.
By default colliders and particles are set in category 0, and their mask allows collisions with all categories.
if ((A.mask & B.category != 0) && (B.mask & A.category) != 0) MayCollide(A,B);
In the following animation the floor colliders are set to collide only with categories 0, 1 and 2, from top to bottom. The cloth balloons are set in categories 0, 1 and 2, from left to right.
All ObiActors allow you to set categories and masks for individual particles. Depending on the actor, this is done in slightly different ways:
Positive thickness values will leave a gap between the collider surface and colliding particles. Negative values will cause particles to "sink" into the collider before actually hitting its surface.
Turns the collider inside out, so particles collide with the inwards side of the collider's surface.
ObiColliders also allow you to set their collision material . This determines how actors react when colliding against them: whether they slip or stop due to friction, or whether they stick to it or not.
This is the Collider that the ObiCollider is exposing to solvers. When you add a ObiCollider component to an object, this field will automatically be populated with the first Collider component found in the object. In cases where you have multiple Collider components in a single object and you want them all to be used by Obi, you must add a ObiCollider for each Collider and manually assign the Source Collider property of each one.
Distance fields (widely known as SDFs) are a special data structure that precomputes and stores distances to the surface of a collider. This gets rid of the need to calculate the distance between particles and the collider analytically during the simulation, making them well suited for efficient and robust collision detection against complex colliders. If you're dealing with a moving and/or complex MeshCollider, consider creating a distance field and assigning it to this property.
When you add an ObiCollider component to an object, it will look for the first Rigidbody component up its hierarchy and attach an ObiRigidbody component to it. This allows for full two-way coupled interaction between Obi particles and rigidbodies. If you delete this component, Obi will recreate it automatically the next time you hit "Play".
ObiRigidbody only has one parameter: "Kinematic for particles". Enabling this shields the rigidbody from any forces applied by particles, so it will behave as if no Obi particles were present in the scene. The particles will still "feel" the rigidbody and collide with it, though.
Enabling particle collision constraints in an ObiSolver component allows particles in the solver to collide with each other. We make a distinction between two kinds of particle collision, depending on which actor the particles involved in the collision belong to: if the particles belong to different actors, it's an inter-collision. If they belong to the same actor, it's a self-collision.
Amount of iterations spent enforcing contacts against other particles during each substep.
Amount of iterations spent smoothing out collision results each substep.
Percentage of particle velocity used to expand their bounding box during collision detection against other particles. A value of 1 will use 100% of the velocity, resulting in full continuous collision detection. A value of 0 will result in purely static collision detection.
Margin added to particle bounding boxes when generating contacts against other particles. Any particles within the particle's bounding box will be considered for contact generation. This value should be kept relatively low. Large values will generate more contacts, which can improve robustness in very complex scenes, but will negatively affect performance.
Amount of iterations spent refining surface collisions against other particles/simplices.
Shock propagation is a technique that modifies particle masses internally during contact resolution, so that particles at the bottom of a pile have higher effective mass that the ones at the top. This results in faster convergence and stabler stacking. Use this when you need an extra "oomph" for your particle-particle contacts, specially when creating stable piles of granular material.
Scales the diffusion speed for each of the 4 user data channels for granular particles. Setting the diffusion mask to zero for specific channel(s) is useful in some situations, for example, when storing custom per-particle data that you don't want to be affected by diffusion.
Provided that the solver has particle collision constraints enabled, ObiActors simulated by that solver will collide with each other. Keep in mind that particles simulated by different solvers will ignore each other, which means actors in different solvers won´t be able to collide with each other.
Softbodies are a special case for intercollisions: each softbody particle stores the direction and distance of the closest point on the surface of the softbody. When directional collisions are enabled for that softbody, particles belonging to other actor(s) that overlap one of the softbody particles won't be projected outside of that particle: they will be projected outside the entire softbody.
This allows for robust depenetration when continuous collision detection fails, and prevents interlocking when two softbodies are instantiated overlapping each other.
Assuming your solver has particle collision constraints enabled, you can allow an actor to collide with itself by enabling the "self-collisions" checkbox in its inspector.