Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Particle Collision Not Working On Instantiated Rope
#6
Hi!

Just realized that your code to iterate over all contacts does this:

Quote:if (contact.distance > 0.01) return;

Which means that once you find the first speculative contact, you exit the function and simply ignore any other contacts.

Same for

Quote:if (particleIndex != hand.SolverIndex) return;

If the first contact in the list is not the one you're looking for, you just stop looking. So your interaction code might or might not work based purely on whether the hand contact is the first one to appear on the list, which is of course 100% luck based Sonrisa.

replace these "return;" with

Quote:continue;

The continue keyword simply jumps to the next iteration of a loop, ignoring all instructions that appear after it in the current iteration. That way, you skip speculative contacts and contacts that you're not interested in, but still process all other contacts to look for the one you want. Still haven't tried the project you sent me but this bug quite likely plays a huge role on the weird behavior you get. Will download the project and try it nonetheless.

Edit: tried the project, and this bug was the culprit indeed. Fixed code:

Code:
// Just iterate over all contacts in the current frame
foreach (Oni.Contact contact in handCollision.contacts)
{
                // This one is an actual collision
                if (contact.distance > 0.01)
                    continue;

                // Get the particle index directly, as all simplices are guaranteed to have size 1:
                int particleIndex = hand.Solver.simplices[contact.bodyA];

                // This is not the particle you are looking for - Obi Wan
                if (particleIndex != hand.SolverIndex) continue;

                // Retrieve collider
                ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

                // Attach hand and collider
                hand.Grab(collider.transform);
}
Reply


Messages In This Thread
RE: Particle Collision Not Working On Instantiated Rope - by josemendez - 21-03-2022, 11:34 AM