04-11-2021, 10:24 AM
(This post was last modified: 04-11-2021, 10:25 AM by dinhtai1104.)
Hi devs, I've just implemented Obi Softbody plugin in game. And I don't know how to detect 2 softbody in scene (With others object is not softbody it's work perfect) here is my scripts for object softbody:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Obi;
public class BallObiCtr : MonoBehaviour
{
public static int BallID = 0;
private int ballID = 0;
public ObiSolver obiSolver;
private void Start()
{
ballID = BallID++;
obiSolver.OnCollision += this.HandleCollisionCallback;
}
private void HandleCollisionCallback(ObiSolver solver, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
// look for actual contacts only:
if (contact.distance < 0.01)
{
var col = world.colliderHandles[contact.bodyB].owner;
if (col != null)
{
Debug.Log(col.name);
if (col.gameObject.transform.CompareTag("Ball"))
{
Debug.Log("Callback collision ball!");
}
}
}
}
}
private void OnDisable()
{
obiSolver.OnCollision -= this.HandleCollisionCallback;
}
}