Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tearing rope on Collision
#1
I am trying to tear the rope using OnCollision callback. The rope does get cut, but it also throws exception error when tearing.

Code:
void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
    {
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            if (e.contacts.Data[i].distance < 0.01f)
            {
                //ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[e.contacts[i].other].owner;
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
                {                   
                    if (collider == scissorCollider)
                    {
                        ObiSolver.ParticleInActor pa = solver.particleToActor[e.contacts.Data[i].particle];

                        if (pa != null)
                        {
                            ropeObject = pa.actor.GetComponent<ObiRope>();
                            ropeElements = ropeObject.elements;
                        }

                        //print(e.contacts.Data[i].particle);

                        for (int j = 0; j < ropeElements.Count; j++)
                        {
                            if( ropeElements[j].particle1 == e.contacts.Data[i].particle )
                            {
                                //print("Contact Particle: "+e.contacts.Data[i].particle);
                                //print("Element Particle: "+ropeObject.elements[j].particle1);

                                int particleToTear = ropeObject.elements[j].particle1;

                                ropeObject.Tear(ropeElements[particleToTear]);
                                ropeObject.RebuildConstraintsFromElements();                               
                            }
                        }                       
                    }
                }
            }
        }
    }

It throws index OutOfRange exception.
Code:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <599589bf4ce248909b8a14cbe4a2034e>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
ScissorCut.Solver_OnCollision (System.Object sender, Obi.ObiSolver+ObiCollisionEventArgs e) (at Assets/Scripts/Cut Logic/ScissorCut.cs:67)
Obi.ObiSolver.EndStep () (at Assets/_IMPORTED/Obi/Scripts/Common/Solver/ObiSolver.cs:1302)
Obi.ObiUpdater.EndStep () (at Assets/_IMPORTED/Obi/Scripts/Common/Updaters/ObiUpdater.cs:104)
Obi.ObiFixedUpdater.FixedUpdate () (at Assets/_IMPORTED/Obi/Scripts/Common/Updaters/ObiFixedUpdater.cs:69)

I can't figure out, please help.
Reply


Messages In This Thread
Tearing rope on Collision - by Spectra_7 - 13-10-2020, 11:41 AM
RE: Tearing rope on Collision - by josemendez - 13-10-2020, 11:43 AM
RE: Tearing rope on Collision - by Spectra_7 - 13-10-2020, 12:00 PM
RE: Tearing rope on Collision - by josemendez - 13-10-2020, 02:29 PM