Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem detecting collisions between two softbodies
#1
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?
Reply
#2
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/tutor...sions.html

let me know how it goes!
Reply
#3
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.
Reply
#4
(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.
Reply
#5
[Image: SlipperyCloudyFieldspaniel-size_restricted.gif]

You're right! Thank you again )
Reply
#6
[Image: 16RK.gif]
Reply