04-02-2021, 12:09 PM
(This post was last modified: 04-02-2021, 12:13 PM by josemendez.)
(04-02-2021, 12:03 PM)Xanduffy Wrote: Hey Jose, thanks for the help again. I'm at a bit of a loss now to be honest, I added the above code and it didn't seem to work, so I added some Debug messages into the grab function to show me where the script was having issues:
Based on that feedback, it seems like there's no collisions being registered between my hand colliders and the rope, despite being able to visibly push the rope around. The only collision feeding from the solver seems to be between the rope and the grappling hook which also has an obi rigidbody for obvious reasons. The rope is set to phase 1, and I reset the hands and the hook to phase 0z so it doesn't appear to be a straightforward issue. I'll add screenshots of the hands, rope and solver inspectors, I hope you can see what's wrong.Code:public void Grab()
{
var world = ObiColliderWorld.GetInstance();
if (solver != null && collisionEvent != null)
{
Debug.Log("Collision");
foreach (Oni.Contact contact in collisionEvent.contacts)
{
if (contact.distance < 0.01f && canGrab)
{
var contactCollider = world.colliderHandles[contact.other].owner;
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
Debug.Log(pa +" hit " + contactCollider);
if (contactCollider == obiCollider)
{
Debug.Log("Hand Collision");
var batch = new ObiPinConstraintsBatch();
int solverIndex = rope.solverIndices[contact.particle];
Vector3 positionWS = solver.transform.TransformPoint(solver.positions[solverIndex]); // particle position from solver to world space
Vector3 positionCS = obiCollider.transform.InverseTransformPoint(positionWS); // particle position from world to collider space
batch.AddConstraint(rope.solverIndices[contact.particle], obiCollider, positionCS, Quaternion.identity, 0, 0, float.PositiveInfinity);
newBatch = batch;
pinConstraints.AddBatch(newBatch);
canGrab = false;
// this will cause the solver to rebuild pin constraints at the beginning of the next frame:
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
}
}
}
}
}
I don't see anything wrong in your screenshots, and the code looks ok to me too.
However, if you're relying on the Debug.Log() in your code to see if there's contacts being reported between your hand and the rope, keep in mind that the Debug.Log() will only be called if canGrab is true. In case your contactCollider is any collider other than the hand collider, and it happens to appear in the contact list before contacts against the hand, canGrab will be set to false and the Debug.Log() for the hand will never be hit despite contacts being there.
This is the only thing that comes to mind that could cause this, since the contact list passed to the collision event is the exact same one used in the simulation. If the hand is able to push the rope around, contacts against it *must* be in the list.
Try testing for canGrab in a separate, nested if() and place the Debug.Log right before it. See if it reports contacts against the hand then.