Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope extension, vibration and collision
#21
(29-04-2025, 11:08 AM)josemendez Wrote: ObiNativeContactList exists in the Obi namespace. Unless you're using a rather old version of the asset, it should be found just fine.


Ok, so you're not using contact callbacks directly then? Which event are you listening for? Keep in mind that this component reports the contact that caused the event, not the particle currently in contact. So if you eg. listen for the "collision enter" event and then move the object in contact with the rope, the contact won't be updated.

kind regards,

I am using version 6.0.1. I put the code in the namespace, even though I searched the whole project, I cannot find this "ObiNativeContactList"

When I bring the end of the rope to the finish area, I activate this code "ObiContactEventDispatcher", I assigned the "OnRopeContactEnter(ObiSolver solver, Oni.Contact contact)" function in another script to the onContactEnter event, so I can get the gameObjects that touch the rope.

What I want next is to create a gameObject at that contact point and move it to the end of the rope.

I want to do this movement as in your suggested "ObiRopeAttach" script. But I can't find the "M" value there correctly. The results, as in the picture I posted before, are irrelevant to the contact points. For example; It can be 0.58 when it should be 0.35f.



Update Info: I managed to get the code to work like this, I'm testing it
Code:
using static Obi.ObiSolver;

namespace Obi
{
    public class RopeContactNormalized : MonoBehaviour
    {
        public ObiRope rope;

        // Start is called before the first frame update
        void Start()
        {
            rope.solver.OnCollision += OnRopeContactEnter;
        }

        public void OnRopeContactEnter(ObiSolver solver, ObiCollisionEventArgs collisionEvent)
        {
            var world = ObiColliderWorld.GetInstance();
            float normalizedCoordinate = -1;

            var contacts = collisionEvent.contacts;

            for (int i = 0; i < contacts.Count; ++i)
            {
                var contact = contacts[i];

                if (contact.distance > 0.001f) continue;

                int particleIndex = solver.simplices[contact.bodyA];
                var col = world.colliderHandles[contact.bodyB].owner;

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

                    int elementIndex = -1;

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

                    if (elementIndex != -1)
                    {
                        normalizedCoordinate = (float)elementIndex / elements.Count;
                        Debug.Log("Normalized rope position: " + normalizedCoordinate);
                        break;
                    }
                    else
                    {
                        Debug.LogWarning("Element not found for particle " + particleIndex);
                    }
                }
                else
                {
                    Debug.LogWarning("Rope reference is missing!");
                }
            }

            if (normalizedCoordinate >= 0)
            {
                var smoother = rope.GetComponent<ObiPathSmoother>();
                if (smoother != null)
                {
                    var section = smoother.GetSectionAt(normalizedCoordinate);
                    Debug.DrawRay(section.position, section.normal, Color.red);
                }
            }
        }

    }
}
Reply


Messages In This Thread
RE: Rope extension, vibration and collision - by 0hsyn1 - 29-04-2025, 11:33 AM