Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision Between 2 SoftBody
#1
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;
    }
}
Reply


Messages In This Thread
Collision Between 2 SoftBody - by dinhtai1104 - 04-11-2021, 10:24 AM
RE: Collision Between 2 SoftBody - by josemendez - 04-11-2021, 10:34 AM
RE: Collision Between 2 SoftBody - by dinhtai1104 - 04-11-2021, 10:35 AM