Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Detect specific rope collision.
#18
(04-07-2022, 02:12 PM)Gauri7 Wrote: yes I am using bodyA and bodyB but it always gives the wrong ropes ( I mean wrong names of colliding ropes )

this is the script :
Code:
using System.Collections;
using System.Collections.Generic;
using Obi;
using UnityEngine;

public class RopeCollision : MonoBehaviour
{

    private ObiSolver _solver;

    private ObiSolver.ObiCollisionEventArgs _collisionEvent;

    private void Awake()
    {
        _solver = GetComponent<ObiSolver>();
    }

    private void OnEnable()
    {
        _solver.OnParticleCollision += Solver_OnParticleCollision;
    }

    private void OnDisable()
    {
        _solver.OnParticleCollision -= Solver_OnParticleCollision;
    }

    private void Solver_OnParticleCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (var contact in e.contacts)
        {
            // this one is an actual collision:
            //Debug.Log(contact.pointA + " pt");
            if (true || contact.distance < 0.01f)
            {
                var pa = _solver.particleToActor[contact.bodyA];
                var po = _solver.particleToActor[contact.bodyB];
              
                if (pa.actor.gameObject != po.actor.gameObject)
                {
                    Debug.Log(pa.actor.gameObject.name + " collides with: " + po.actor.gameObject.name);
                }
            }


        }
    }
}

bodyA and bodyB are simplex indices, cannot be used to access the particleToActor array directly. You must get the particle index from the simplex index first. Check the sample code in the manual, the link I provided in the previous post.

Cheers!
Reply


Messages In This Thread
Detect specific rope collision. - by flaurens - 05-10-2020, 08:45 AM
RE: Detect specific rope collision. - by flaurens - 05-10-2020, 12:18 PM
RE: Detect specific rope collision. - by Elegar - 09-11-2020, 09:53 PM
RE: Detect specific rope collision. - by Elegar - 11-11-2020, 12:16 PM
RE: Detect specific rope collision. - by Gauri7 - 04-07-2022, 11:57 AM
RE: Detect specific rope collision. - by Gauri7 - 04-07-2022, 02:12 PM
RE: Detect specific rope collision. - by josemendez - 04-07-2022, 07:52 PM
RE: Detect specific rope collision. - by Gauri7 - 05-07-2022, 09:33 AM
RE: Detect specific rope collision. - by Gauri7 - 06-07-2022, 12:20 PM
RE: Detect specific rope collision. - by Gauri7 - 08-07-2022, 09:35 AM