Obi Official Forum
Problem detecting collisions between two softbodies - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Softbody (https://obi.virtualmethodstudio.com/forum/forum-12.html)
+--- Thread: Problem detecting collisions between two softbodies (/thread-2798.html)



Problem detecting collisions between two softbodies - the-lander - 10-03-2021

Hello.
I have a problem detecting when two softbodies collide. Here's the code I use and the video of the result: https://drive.google.com/file/bla-bla-bla

Code:
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        player_is_grounded = false;

        var world = ObiColliderWorld.GetInstance();
        foreach (var contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                var pa = solver.particleToActor[contact.bodyA];
                var po = solver.particleToActor[contact.bodyB];
                if (pa.actor.gameObject != po.actor.gameObject)
                {
                    Debug.Log(pa.actor.gameObject.name + " + " + po.actor.gameObject.name);
                }
            }
        }
    }

For some reason when the blue sheep hits the ground it starts sending message that it's colliding with the player, who's still in midair falling few units away. How there's a collision between these two objects if they're apart?


RE: Problem detecting collisions between two softbodies - josemendez - 11-03-2021

This code doesn't make much sense. You're indexing the particleToActor arrays using contact.bodyA and contact.bodyB that are simplex indices, not particle indices. So it will check unrelated particles at best, or result in an out of bounds access exception at worst. My guess is that it's checking the sheep against itself.

It should be:

Code:
var pa = solver.particleToActor[solver.simplices[contact.bodyA]];
var po = solver.particleToActor[solver.simplices[contact.bodyB]];

See "Retrieving the particle involved in a contact" in the manual:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html

let me know how it goes!


RE: Problem detecting collisions between two softbodies - the-lander - 11-03-2021

The situation didn't change at all. Console still shows "Sheep + Player" text when and only if both of them touch the Ground, which has Obi Collider component.

I've tried to copy this solution but is doesn't work for me.


RE: Problem detecting collisions between two softbodies - josemendez - 11-03-2021

(11-03-2021, 10:20 PM)the-lander Wrote: The situation didn't change at all. Console still shows "Sheep + Player" text when and only if both of them touch the Ground, which has Obi Collider component.

I've tried to copy this solution but is doesn't work for me.

Could it be that you’re subscribing to the OnCollision event, instead of OnParticleCollision? The first will report particle-collider contacts, the second one particle-particle contacts (which is what you’re interested in)

Its the only cause I can think of, otherwise it makes no sense for the debug.log to be called when both touch a collider.


RE: Problem detecting collisions between two softbodies - the-lander - 12-03-2021

[Image: SlipperyCloudyFieldspaniel-size_restricted.gif]

You're right! Thank you again )


RE: Problem detecting collisions between two softbodies - josemendez - 12-03-2021

[Image: 16RK.gif]