Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope extension, vibration and collision
#11
(28-04-2025, 08:07 AM)josemendez Wrote: contact.bodyA is not a particle index. To get the index of the particle in the actor, use the solver.simplices array and then look up solver.particleInActor to get the index of that particle in the rope. See "Retrieving the particle involved in a contact" in the manual: https://obi.virtualmethodstudio.com/manu...sions.html


If you're altering the topology of the rope in any way (extending/retracting/cutting the rope) the above approach using particles won't work. The reason is that there's no guarantee new particles (added when extending the rope) will be added at the end/start of the rope, so their indices may be unordered. You must use elements instead as explained in the manual: https://obi.virtualmethodstudio.com/manu...ropes.html

The approach is similar: get a particle index from the contact, then iterate over all elements until you find the one that references that particle. Once you have the index of the desired element, divide it by the number of elements in the rope to get the normalized coordinate.


Simply reloading the original rope blueprint (by assigning it to rope.ropeBlueprint) should do it.

kind regards,

I wrote such a code according to the document you gave me but the result is negative, what should I fix?
Code:
public void OnRopeContactEnter(ObiSolver solver, Oni.Contact contact)
{
    var world = ObiColliderWorld.GetInstance();
    var col = world.colliderHandles[contact.bodyB].owner;

    if (col != null && col.GetComponent<Item>() != null && !col.GetComponent<Item>().ColliderTriggerControl())
    {
        if (!GameManager.instance.usedItems.Contains(col.GetComponent<Item>()))
        {
            GameManager.instance.UsedItemsAdd(col.GetComponent<Item>());
           
            int particleIndex = solver.simplices[contact.bodyA];

            ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
           

            if (rope != null)
            {
               
                var elements = rope.elements;

                int elementIndex = -1;

                for (int i = 0; i < elements.Count; ++i)
                {
                    var element = elements[i];
                    if (element.particle1 == pa.indexInActor || element.particle2 == pa.indexInActor)
                    {
                        elementIndex = i;
                        break;
                    }
                }

                if (elementIndex != -1)
                {
                    float normalizedCoordinate = (float)elementIndex / elements.Count;
                    Debug.Log("Normalized rope position: " + normalizedCoordinate);

                   
                }
                else
                {
                    Debug.LogWarning("Element not found for particle " + particleIndex);
                }
            }
            else
            {
                Debug.LogWarning("Rope reference is missing!");
            }
}
Reply


Messages In This Thread
RE: Rope extension, vibration and collision - by 0hsyn1 - 28-04-2025, 09:13 AM