Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Check ropes touching each other
#6
(30-11-2021, 04:36 PM)greyhawk Wrote: I am getting the following error. What am I doing wrong?

Hi!

Contacts can be between a simplex and a collider, or between two simplices. If you subscribe to solver.OnCollision, contact.bodyA will always be a simplex index and contact.bodyB will always be a collider index. See: http://obi.virtualmethodstudio.com/manua...sions.html

Quote:BodyA: Index of the first simplex involved in the contact.

BodyB: Index of the collider / second simplex involved in the contact. In case of simplex-collider contacts, this index can be used to retrieve the actual collider object, see below.

If you subscribe to solver.OnParticleCollision, both bodyA and bodyB will always be simplex indices. For some reason, in your code you're using bodyA and bodyB to try and access the global collider array:

Code:
ObiColliderBase colB = world.colliderHandles[contact.bodyB].owner;
ObiColliderBase colA = world.colliderHandles[contact.bodyA].owner;

Which will almost always cause an out of range exception.

To understand why, think about what would happen if you had 3 colliders and 10 simplices in your scene: if simplices 5 and 9 collide with each other, you will get a contact such that bodyA is 5 and bodyB is 9. You then try to access positions 5 and 9 in the world.colliderHandles array that only has 3 entries (because there's only 3 colliders in the scene), so you're essentially asking Unity to access data that doesn't exist ----> the error is trying to tell you that the index used to access that array is out of range: to access an array of size 3, you can only use indices 0,1 and 2.

This code deals with simplex-simplex collisions, so no need to check for colliders.

Code:
foreach (Oni.Contact contact in e.contacts)
{
               
     int particleIndexA = solver.simplices[contact.bodyA];
     int particleIndexB = solver.simplices[contact.bodyB];

// retrieve the actor this particle belongs to:
     ObiSolver.ParticleInActor paA = solver.particleToActor[particleIndexA];
     ObiSolver.ParticleInActor paB = solver.particleToActor[particleIndexB];
     var actorA = paA.actor as ObiRope;
     var actorB = paB.actor as ObiRope;
     actorA.GetComponent<RopeController>().CheckContact(actorB);
}
Reply


Messages In This Thread
Check ropes touching each other - by greyhawk - 27-11-2021, 02:20 PM
RE: Check ropes touching each other - by greyhawk - 30-11-2021, 02:09 PM
RE: Check ropes touching each other - by greyhawk - 30-11-2021, 04:36 PM
RE: Check ropes touching each other - by josemendez - 01-12-2021, 08:32 AM
RE: Check ropes touching each other - by greyhawk - 01-12-2021, 02:34 PM