Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Collision detection with particles (strange behaviour)
#1
Code:
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.025f)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;

                if (col != null && col.gameObject.layer==LayerMask.NameToLayer("CarFrontCollider"))
                {
                    // get the index of the particle involved in the contact:
                    int particleIndex = solver.simplices[contact.bodyA];
                    ObiRope contactedRope = solver.particleToActor[particleIndex].actor as ObiRope;
                    contactedRope.GetComponent<SpecificRopeTearer>().TearRope(particleIndex);        
                }
            }
        }
    }

Code:
public void TearRope(int particleIndex)
        {
        this.GetComponent<RopeBehaviour>().enabled = false;

        if (this.didTear == false)
        {
            BusSystem.CallOnRopeToreApart(this.endParticle.target.GetComponent<FuelLineEndController>());
            StartCoroutine(DestroyRope());
                        this.rope.stretchingScale = 1f;
                        this.endParticle.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
                        this.endParticle.target = this.rope.transform;
                        this.startParticle.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
                        this.startParticle.target = this.rope.transform;

                        this.didTear = true;
        }

        this.TearAtIndex(particleIndex);
    }

void TearAtIndex(int index)
    {
        Debug.Log(index);

        if (index < rope.elements.Count)
        {
            this.rope.Tear(rope.elements[index]);
        }


        this.rope.RebuildConstraintsFromElements();
    }


Hi ! I am working on a project and using ObiRope. I have problem with detecting collision with particles. I read documents and tried to use them as best as I can. 

I need to know which particle collided with a object that has specific layer. And I want to tear the rope at collided particles. Here is some screenshots for explaining it better. At right (teared rope) image behaviour acts like I want. But after I spawn new ropes it doesn't work. When I am Debug.Log the shown indexes are beyond existing particle count (I may be wrong in here.).


If you need any additional info please tell me, I don't want to scare people with a long post  Sonrisa

Thank you !

I think I solved it Gran sonrisa. Just changed parameter "particleIndex" to "this.solver.particleToActor[particleIndex].indexInActor"  Sonrisa I think I solved it Gran sonrisa. Still don't have idea why it didn't work.

Code:
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.025f)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;

                if (col != null && col.gameObject.layer==LayerMask.NameToLayer("CarFrontCollider"))
                {
                    // get the index of the particle involved in the contact:
                    int particleIndex = solver.simplices[contact.bodyA];
                    ObiRope contactedRope = solver.particleToActor[particleIndex].actor as ObiRope;
                    contactedRope.GetComponent<SpecificRopeTearer>().TearRope(this.solver.particleToActor[particleIndex].indexInActor); ;
                }
            }
        }
    }


Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
Collision detection with particles (strange behaviour) - by immrkuby - 05-08-2021, 09:09 PM