Obi Official Forum
Help cloth-rope collision - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Help cloth-rope collision (/thread-3414.html)



cloth-rope collision - maygdirf - 21-04-2022

Hi!
It's possible to detect cloth-rope collisions? I have a cloth that simulates a piece of tissue and i would be able to create a needle with a thread that penetrates the cloth. In so doing, I'm not able to detect the particle collisions between the two. Am I doing something wrong?


RE: cloth-rope collision - josemendez - 21-04-2022

(21-04-2022, 10:31 AM)maygdirf Wrote: Hi!
It's possible to detect cloth-rope collisions? I have a cloth that simulates a piece of tissue and i would be able to create a needle with a thread that penetrates the cloth. In so doing, I'm not able to detect the particle collisions between the two. Am I doing something wrong?

Hi there,

Collisions between actors (rope and cloth, for instance) should happen automatically by default, unless you have changed the collision filters in either actor to specify otherwise.

You talk about "detecting the particle collisions", so I take it you're using a script to detect the contacts at runtime? can you share the script you're using?


RE: cloth-rope collision - maygdirf - 21-04-2022

(21-04-2022, 10:37 AM)josemendez Wrote: Hi there,

Collisions between actors (rope and cloth, for instance) should happen automatically by default, unless you have changed the collision filters in either actor to specify otherwise.

You talk about "detecting the particle collisions", so I take it you're using a script to detect the contacts at runtime? can you share the script you're using?
Code:
private void Awake()
    {
        solver = this.GetComponentInParent<ObiSolver>();
    }

    private void OnEnable()
    {
        solver.OnCollision += Solver_OnCollision;
    }

    private void OnDisable()
    {
        solver.OnCollision -= Solver_OnCollision;
    }

    public void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        foreach(Oni.Contact contact in e.contacts)
        {
            ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

            if (collider.CompareTag("Rope") && collider != null)
            {
                int particleIndex = solver.simplices[contact.bodyA];
                if (!(contactParticles.Contains(particleIndex)))
                    AddIndex(particleIndex, e);


                stitcher.AddStitch(particleIndex, solver.simplices[contact.bodyB]);
                stitcher.PushDataToSolver();
            }
This is part of my code. I would like to use the stitcher to attach the two obi actors. I think that something stupid is wrong in this code but I don't know what. Thanks for the help!


RE: cloth-rope collision - josemendez - 21-04-2022

You're subscribed to solver.OnCollision, instead of solver.OnParticleCollision. So your code is looking at the collisions between particles and colliders, not particle-particle collisions. Sonrisa

cheers!


RE: cloth-rope collision - maygdirf - 21-04-2022

(21-04-2022, 11:21 AM)josemendez Wrote: You're subscribed to solver.OnCollision, instead of solver.OnParticleCollision. So your code is looking at the collisions between particles and colliders, not particle-particle collisions. Sonrisa

cheers!
Nice! I'm stupid  Gran sonrisa

But the subscription to the Solver_OnCollision function remains the same?


RE: cloth-rope collision - josemendez - 21-04-2022

(21-04-2022, 01:47 PM)maygdirf Wrote: But the subscription to the Solver_OnCollision function remains the same?

In C#, the name of the function subscribed to an event can be any you like. Solver_OnCollision is the one that Visual Studio automatically creates for you, but you could name it “MyColourfulFunction” and it would be fine Sonrisa


RE: cloth-rope collision - maygdirf - 21-04-2022

(21-04-2022, 02:30 PM)josemendez Wrote: In C#, the name of the function subscribed to an event can be any you like. Solver_OnCollision is the one that Visual Studio automatically creates for you, but you could name it “MyColourfulFunction” and it would be fine Sonrisa
Yes, of course. I meant, like the one I have written in the code above! Ahahah