Thanks for the reply.
Like you said, I got it work the way I wanted. I am dropping the script here in case someone finds it useful:
Thanks a lot.
Like you said, I got it work the way I wanted. I am dropping the script here in case someone finds it useful:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
public class RopeTriggerCheck : MonoBehaviour
{
public ObiSolver solver;
public ObiActor ropeActor;
public Collider triggerCollider;
public float currentParticlesCount = 0;
public float totalParticlesCount;
public bool isEventTriggered;
public List<int> particlesEnteredList = new List<int>();
private ObiRopeBlueprint ropeBlueprint;
private void Start()
{
if(ropeActor == null)
ropeActor = solver.actors[0];
ropeBlueprint = (ObiRopeBlueprint)ropeActor.blueprint;
totalParticlesCount = ropeBlueprint.activeParticleCount;
isEventTriggered = false;
}
private void OnEnable()
{
solver.OnCollision += Solver_OnCollision;
}
private void OnDisable()
{
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
//print(e.contacts.Count);
for (int i = 0; i < e.contacts.Count; ++i)
{
if (e.contacts.Data[i].distance < 0.01f)
{
Component collider;
if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
{
if (collider == triggerCollider)
{
if(!particlesEnteredList.Contains(e.contacts.Data[i].particle))
particlesEnteredList.Add(e.contacts.Data[i].particle);
currentParticlesCount = particlesEnteredList.Count;
if(currentParticlesCount >= totalParticlesCount && !isEventTriggered)
{
//Trigger an Event you like
isEventTriggered = true;
}
}
}
}
}
}
}
Thanks a lot.