Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Fluid Collision Callback never ending
#1
Triste 
Im new to Obi and i have a problem with the collisions.

I have a flask which is generating a liquid(Obi Emiiter) and a floor (Obi Collider) that interacts with that liquid.
I made different floors each one with the PhLandController script that i only want to call when the liquid collides  with the floor
I also have an (Obi Solver) which have the following script.



Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class FluidPhCollisionHandler : MonoBehaviour {

    ObiSolver solver;
    PhLandController phController;

    void Awake(){
        solver = GetComponent<Obi.ObiSolver>();
    }

    void OnEnable () {
        solver.OnCollision += Solver_OnCollision;
    }

    void OnDisable(){
        solver.OnCollision -= Solver_OnCollision;
    }

    void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        Oni.Contact contact = e.contacts[0];

        Component collider;
        if (ObiCollider.idToCollider.TryGetValue(contact.other,out collider)){
            phController = collider.GetComponent<PhLandController>();
            phController.increasePHLevel();
        }
    }



}

The problems is that after i remove the liquid from colliding to the floor the method increasePHLevel() is call infinitly.
The only way to stop it is that the liquid begins a new collision with a different floor but the problem is now pass to the new floor method is call infinitly.


Any suggestion how i could fix this ?

Thanks
Reply
#2
(29-09-2019, 11:40 PM)RjcArci Wrote: Im new to Obi and i have a problem with the collisions.

I have a flask which is generating a liquid(Obi Emiiter) and a floor (Obi Collider) that interacts with that liquid.
I made different floors each one with the PhLandController script that i only want to call when the liquid collides  with the floor
I also have an (Obi Solver) which have the following script.



Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class FluidPhCollisionHandler : MonoBehaviour {

ObiSolver solver;
PhLandController phController;

void Awake(){
solver = GetComponent<Obi.ObiSolver>();
}

void OnEnable () {
solver.OnCollision += Solver_OnCollision;
}

void OnDisable(){
solver.OnCollision -= Solver_OnCollision;
}

void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
Oni.Contact contact = e.contacts[0];

Component collider;
if (ObiCollider.idToCollider.TryGetValue(contact.other,out collider)){
phController = collider.GetComponent<PhLandController>();
phController.increasePHLevel();
}
}



}

The problems is that after i remove the liquid from colliding to the floor the method increasePHLevel() is call infinitly.
The only way to stop it is that the liquid begins a new collision with a different floor but the problem is now pass to the new floor method is call infinitly.


Any suggestion how i could fix this ?

Thanks

Hi,

We'd need to see exactly how you "remove the liquid from colliding" to tell what's happening. Keep in mind that Obi uses speculative contacts, because of this many contacts in a frame do not progress to actual collisions. You should test for contact distance and discard those that aren't actual contacts. See:
http://obi.virtualmethodstudio.com/tutor...sions.html

If you're only interested in the first contact, you should also check if there's at least one contact, or you will get a out of bounds exception.
Reply