Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Simple Collision Debug Log
#1
Pregunta 
Hello,

I am able to make fluid collide with 3D objects using the Obi Colliders, but I have yet to figure out how to get any data back from the collision itself. 
Even just a Debug.Log("Foo") would be enough to get me in the right direction.

Here's the code snippet in the documentation that I first started messing around with:
Code:
ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

Any step-by-step instructions would be great. Thanks!
Reply
#2
(25-01-2026, 05:38 PM)PortableAnswers Wrote: Here's the code snippet in the documentation that I first started messing around with:
Code:
ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

Any step-by-step instructions would be great. Thanks!

Hi!

Assuming you're just using that one line of code, all it does is retrieve a reference to a collider. You're not subscribing to the contact callback event, and not checking any contacts. Try the full snippet:

Code:
using UnityEngine;
using Obi;

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

    ObiSolver solver;

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

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

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

    void Solver_OnCollision (object sender, ObiNativeContactList e)
    {
        var world = ObiColliderWorld.GetInstance();

        // just iterate over all contacts in the current frame:
        foreach (Oni.Contact contact in e)
        {
            // if this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
                if (col != null)
                {
                    // do something with the collider.
                        Debug.Log("Foo");
                }
            }
        }
    }

}

let me know if you need further help,

kind regards
Reply