Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope extension, vibration and collision
#12
(28-04-2025, 09:13 AM)0hsyn1 Wrote: I wrote such a code according to the document you gave me but the result is negative, what should I fix?

Elements contain indices of particles in the solver, not the actor. Here's the fixed code:

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];

            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 == particleIndex || element.particle2 == particleIndex)
                    {
                        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 josemendez - 28-04-2025, 09:30 AM