Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  bodyA on Solver_OnCollision yielding arbitrary index
#1
I am using Solver_OnCollision on CollisionEventHandler to discover colliding OBI bodies.
contact.bodyB provides the correct index = 2
However, contact.bodyA provides an arbitrary index of 352, which is well beyond the count of world.colliderHandles (there are 3).

Can you please advise? Code attached.

void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{


var world = ObiColliderWorld.GetInstance();

// just iterate over all contacts in the current frame:
foreach (Oni.Contact contact in e.contacts)
{

// if this one is an actual collision:
if (contact.distance < 0.001f)
{

ObiColliderBase HitCollider = world.colliderHandles[contact.bodyB].owner;
if (HitCollider != null && HitCollider.gameObject.tag != "Tether")
{
Debug.Log("Body count = " + world.colliderHandles.Count); // returns 3
Debug.Log("bodyA = " + contact.bodyA); // returns 352
Debug.Log("bodyB = " + contact.bodyB); // returns 2

if (world.colliderHandles[contact.bodyB].owner != null)
{

Debug.Log(HitCollider.gameObject.name);
}

}
}
}
}
Reply
#2
(27-05-2023, 06:09 AM)michendo Wrote: I am using Solver_OnCollision on CollisionEventHandler to discover colliding OBI bodies.
contact.bodyB provides the correct index = 2
However, contact.bodyA provides an arbitrary index of 352, which is well beyond the count of world.colliderHandles (there are 3).

Can you please advise? Code attached.

    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {


        var world = ObiColliderWorld.GetInstance();

        // just iterate over all contacts in the current frame:
        foreach (Oni.Contact contact in e.contacts)
        {

            // if this one is an actual collision:
            if (contact.distance < 0.001f)
            {
               
                ObiColliderBase HitCollider = world.colliderHandles[contact.bodyB].owner;
                if (HitCollider != null && HitCollider.gameObject.tag != "Tether")
                {
                    Debug.Log("Body count = " + world.colliderHandles.Count); // returns 3
                    Debug.Log("bodyA = " + contact.bodyA);      // returns 352
                    Debug.Log("bodyB = " + contact.bodyB);      // returns 2

                    if (world.colliderHandles[contact.bodyB].owner != null)
                    {

                        Debug.Log(HitCollider.gameObject.name);
                    }

                }
            }
        }
    }

Hi!

Obi only deals with particles and Unity’s collider components. Particles and colliders are collectively referred to as “bodies”.

In the case of particle-collider contacts, bodyA is a simplex index, bodyB is a collider index.
In case of particle-particle contacts, both bodyA and bodyB are simplex indices.

In no case bodyA is a collider index. See the documentation for details:
http://obi.virtualmethodstudio.com/manua...sions.html

By default (unless your cloth uses surface collisions) cloth simplices are made of one particle each. bodyA = 352 and bodyB = 2 means particle #352 in a cloth actor is colliding against collider #2.
Let me know if you need further help,

Kind regards
Reply