Obi Official Forum
ObiRope 3.2 Collision Position - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: ObiRope 3.2 Collision Position (/thread-123.html)



ObiRope 3.2 Collision Position - tbookout - 10-09-2017

These are changes I made to determine where a Rope particle hit a Unity Collider in 3.2.
If someone has better solution please chime in!

Code:
 void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           if (contact.distance < 0.01)
           {
               //Collider collider = solver.colliderGroup.colliders[contact.other];  **Obi 3.1
               Collider collider = ObiCollider.idToCollider[contact.other] as Collider;
               ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];

To get ObiRope = pa.actor
To get index of Particle = pa.indexInActor,
To get collision point of Collider = collider.transform.InverseTransformPoint(contact.point));
(I use the above to Pin particle to object that was collided with)

To get ObiCollider = collider.gameObject.GetComponent<ObiCollider>();


               
*EDIT* Just noticed that niZmo's code works for 3.2 as well.  You can find a complete solution here: ObiRope 3.2+ and VRTK 3.3.0 alpha+