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
#2
Hi,

Subscribe to OnParticleCollision instead of OnCollision. See the manual:
http://obi.virtualmethodstudio.com/manua...sions.html

Quote:To request the simplex-collider contact list from the solver, subscribe to its OnCollision event. To retrieve the simplex-simplex contact list, subscribe to its OnParticleCollision event.
Reply
#3
(04-11-2021, 10:34 AM)josemendez Wrote: Hi,

Subscribe to OnParticleCollision instead of OnCollision. See the manual:
http://obi.virtualmethodstudio.com/manua...sions.html
Fast reply, thanks

(04-11-2021, 10:34 AM)josemendez Wrote: Hi,

Subscribe to OnParticleCollision instead of OnCollision. See the manual:
http://obi.virtualmethodstudio.com/manua...sions.html
Can you show me a sample about it, I change OnCollision to OnParticleCollision but it appears some error at line
Code:
var col = world.colliderHandles[contact.bodyB].owner;
Error is:
Quote:ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <9577ac7a62ef43179789031239ba8798>:0)
BallObiCtr.HandleCollisionCallback (Obi.ObiSolver solver, Obi.ObiSolver+ObiCollisionEventArgs e) (at Assets/BallObiCtr.cs:29)
Obi.ObiSolver.EndStep (System.Single substepTime) (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1582)
Obi.ObiUpdater.EndStep (System.Single substepDeltaTime) (at Assets/Obi/Scripts/Common/Updaters/ObiUpdater.cs:92)
Obi.ObiFixedUpdater.FixedUpdate () (at Assets/Obi/Scripts/Common/Updaters/ObiFixedUpdater.cs:52)
Reply