Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Check ropes touching each other
#5
(30-11-2021, 02:28 PM)josemendez Wrote: Hi!

Simple: when the contact no longer appears in the list.

You can compare the previous frame's contact list and the current contact list to determine enter, stay and exit events. This is what the ObiContactEventDispatcher utility component does for regular -collider- contacts. You can do the same for particle contacts too.
I am getting the following error. What am I doing wrong?
"ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
_Game.Scripts.Entities.Rope.RopeCutter.Solver_OnParticleCollision (System.Object sender, Obi.ObiSolver+ObiCollisionEventArgs e) (at Assets/_Game/Scripts/Entities/Rope/RopeCutter.cs:95)
Obi.ObiSolver.EndStep (System.Single substepTime) (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1598)
Obi.ObiUpdater.EndStep (System.Single substepDeltaTime) (at Assets/Obi/Scripts/Common/Updaters/ObiUpdater.cs:92)
Obi.ObiFixedUpdater.FixedUpdate () (at Assets/Obi/Scripts/Common/Updaters/ObiFixedUpdater.cs:52)
"

Code:
void Solver_OnParticleCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
        {
            var world = ObiColliderWorld.GetInstance();

            // just iterate over all contacts in the current frame:
            foreach (Oni.Contact contact in e.contacts)
            {
                // if this one is an actual collision:
                Debug.Log(contact.bodyB);
                Debug.Log(contact.bodyA);
                ObiColliderBase colB = world.colliderHandles[contact.bodyB].owner;
                ObiColliderBase colA = world.colliderHandles[contact.bodyA].owner;
                if (colA != null && colB != null)
                {
                    int particleIndexA = solver.simplices[contact.bodyA];
                    int particleIndexB = solver.simplices[contact.bodyB];
// retrieve the actor this particle belongs to:
                    ObiSolver.ParticleInActor paA = solver.particleToActor[particleIndexA];
                    ObiSolver.ParticleInActor paB = solver.particleToActor[particleIndexB];
                    var actorA = paA.actor as ObiRope;
                    var actorB = paB.actor as ObiRope;
                    actorA.GetComponent<RopeController>().CheckContact(actorB);
                }
            }
        }

Code:
[SerializeField] public List<ObiRope> contactList;
        private bool justOnce;
        float t=0;
       
        private void Update()
        {
            t += Time.deltaTime;
            if (t > 10)
            {
                if (contactList.Count>0)
                {
                    contactList.Clear();
                    justOnce = true;
                }
                else
                {
                    _signalBus.Fire(new RopeUncontactSignal());
                    justOnce = true;
                }
                t = 0;
            }
        }

        public void CheckContact(ObiRope rope)
        {
            foreach (var contact in contactList)
            {
                if (contact==rope)
                {
                    return;
                }
                contactList.Add(rope);
                if (justOnce)
                {
                    _signalBus.Fire(new RopeContactSignal());
                    justOnce=false;
                }
            }
        }
Reply


Messages In This Thread
Check ropes touching each other - by greyhawk - 27-11-2021, 02:20 PM
RE: Check ropes touching each other - by greyhawk - 30-11-2021, 02:09 PM
RE: Check ropes touching each other - by greyhawk - 30-11-2021, 04:36 PM
RE: Check ropes touching each other - by greyhawk - 01-12-2021, 02:34 PM