28-04-2025, 09:54 AM
(28-04-2025, 09:30 AM)josemendez Wrote: Elements contain indices of particles in the solver, not the actor. Here's the fixed code:This piece of code didn't help either :/
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!");
}
}
I also encountered a problem with the rope reset part. If the rope is wrapped around an object, it does not reset, but I can reset it when it is idle.