04-02-2021, 12:03 PM
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);
}
}
}
}
}