Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  please help
#1
I want to find out objects which  a softbody ball hits at the same time. Huh
Reply
#2
(25-03-2022, 07:57 PM)Alikemalerdem Wrote: I want to find out objects which  a softbody ball hits at the same time. Huh

Hi there,

You can get a list of all contacts between particles and colliders by subcribing to the solver.OnCollision event. See: http://obi.virtualmethodstudio.com/manua...sions.html
Reply
#3
(26-03-2022, 12:03 AM)josemendez Wrote: Hi there,

You can get a list of all contacts between particles and colliders by subcribing to the solver.OnCollision event. See: http://obi.virtualmethodstudio.com/manua...sions.html
I think the information I was looking for is not available at this address. Can you explain it to me? i.e. how do I get all the objects that hit the object?
Reply
#4
(26-03-2022, 08:17 AM)Alikemalerdem Wrote: I think the information I was looking for is not available at this address. Can you explain it to me? i.e. how do I get all the objects that hit the object?

Hi,

That page I linked to explains how to get all contacts between objects, and how to retrieve the pair of objects involved in each contact. This is what you are asking for, I believe.

See “Retrieving the collider involved in a contact” and “Retrieving the actor involved in a contact” in that page.

Kind regards,
Reply
#5
Code:
using UnityEngine;
using Obi;

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

    ObiSolver solver;
        GameObject collision;

    void Awake(){
        solver = GetComponent&ltObiSolver>();
    }

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

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

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

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

}

here collision object takes only one value but I want to get all the objects that hit the object.
Reply
#6
(26-03-2022, 03:22 PM)Alikemalerdem Wrote: here collision object takes only one value but I want to get all the objects that hit the object.

Hi,

This is a for loop over all contacts. It will get you all the object/softbody collision pairs in the solver.

As a side note, this line of code doesn’t make any sense to me:

Code:
collision=gameObject.Find(col.name);

“col” is a component on the collider gameobject, so no need to find it by name in the entire scene. You already have a reference to it, so just do

Code:
collision = col.gameObject;

If you’re unfamiliar with C# scripting, my advice would be to learn the basics first before using Obi, as it assumes you have intermediate programming skills. Otherwise you will find it very hard and confusing to use.

Kind regards,
Reply
#7
Thanks problem is solved.
Reply