23-03-2022, 02:27 AM
(21-03-2022, 11:34 AM)josemendez Wrote: Hi!
Just realized that your code to iterate over all contacts does this:
Which means that once you find the first speculative contact, you exit the function and simply ignore any other contacts.
Same for
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 .
replace these "return;" with
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);
}
Ah, of course! What a trivial mistake and thank you so much for looking into this and replying back with the solution!