24-11-2021, 01:31 PM
(This post was last modified: 24-11-2021, 01:32 PM by josemendez.)
(24-11-2021, 01:02 PM)Romahaaa Wrote: Ok, so I got this point on the bank note surface, but this point is pretty far (screenshot) from the actual particle positions. How can I apply the movement to the bank note? Checking ObiParticleDragger I see that it apply force to the single particle, but it's not always will be correct. Is there an east way to find the opposite particle and add force to both of them?
When you use surface collisions, the contact information given by raycast queries includes the index of the simplex hit. (if you're unsure of what a simplex is, check the surface collisions page)
The simplex in the case of cloth is a triangle, and it contains the 3 indices of the particles in it. See the examples in the queries manual page, specifically the single raycast one. Pasting it here for convenience:
Code:
// perform a raycast, check if it hit anything:
if (solver.Raycast(new Ray(Vector3.zero, Vector3.up), out QueryResult result, filter, 50, 0.1f))
{
// get the start and size of the simplex that was hit:
int simplexStart = solver.simplexCounts.GetSimplexStartAndSize(result.simplexIndex, out int simplexSize);
// Debug draw the simplex:
for (int i = 0; i < simplexSize; ++i)
{
int particleIndex = solver.simplices[simplexStart + i];
Vector3 pos = solver.transform.TransformPoint(solver.positions[particleIndex]);
Debug.DrawRay(pos, Vector3.up, Color.yellow);
}
}
As you see, the code casts a ray and as a result you get the index of the simplex and the size of the simplex (for cloth is always 3, since it's made of triangles). Then the code iterates trough the simplices to draw them.
Having the simplex, then you can do one of several things: move all 3 particles in it, or use barycentric coordinates to apply different forces to each one, depending on the kind of interaction you're after.
Let me know if you need further help .