Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solver_OnCollision: Distinguish between Obi Types at collision
#1
Hi,

I use this code on our ObiSolver to let the player character interact with Obi SoftBodies:

Code:
   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           // this one is an actual collision:
           if (contact.distance < 0.01)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
               {
                   if (collider.transform.gameObject.CompareTag("Player"))
                   {
                       Vector3 direction = new Vector3(contact.point.x, contact.point.y, contact.point.z) - collider.transform.position;
                       direction.Normalize();
                       direction = direction * 200f;

                       Solver.externalForces[contact.particle] = new Vector4(direction.x, Random.Range(0f, 200f), direction.z, Random.Range(10f, 20f));
                   }
               }
           }
       }
   }


It looks pretty much perfect in our use-case. Unfortunately, we have problems making this compatible with ObiRopes as well, because the Solver_OnCollision event does not distinguish between Obi Types. We want to have other values if the player touches soft-bodies or ropes.

I initially thought that would be what the sender component is used for, but strangely a Debug.Log(sender) only returns ObiSolver(Obi.ObiSolver). Am I missing something? Could this be added as a feature? I think it is quite essential if you have both assets.

Best regards and honest thanks for your always great support,
Daniel
Reply
#2
(06-11-2019, 04:30 PM)HenryChinaski Wrote: Hi,

I use this code on our ObiSolver to let the player character interact with Obi SoftBodies:

Code:
   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           // this one is an actual collision:
           if (contact.distance < 0.01)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
               {
                   if (collider.transform.gameObject.CompareTag("Player"))
                   {
                       Vector3 direction = new Vector3(contact.point.x, contact.point.y, contact.point.z) - collider.transform.position;
                       direction.Normalize();
                       direction = direction * 200f;

                       Solver.externalForces[contact.particle] = new Vector4(direction.x, Random.Range(0f, 200f), direction.z, Random.Range(10f, 20f));
                   }
               }
           }
       }
   }


It looks pretty much perfect in our use-case. Unfortunately, we have problems making this compatible with ObiRopes as well, because the Solver_OnCollision event does not distinguish between Obi Types. We want to have other values if the player touches soft-bodies or ropes.

I initially thought that would be what the sender component is used for, but strangely a Debug.Log(sender) only returns ObiSolver(Obi.ObiSolver). Am I missing something? Could this be added as a feature? I think it is quite essential if you have both assets.

Best regards and honest thanks for your always great support,
Daniel

Hi,

You can easily retrieve which actor a particle belongs to. See "Retrieving the actor involved in a contact" in:
http://obi.virtualmethodstudio.com/tutor...sions.html

once you have the ObiActor (which is the base class for ObiCloth,ObiEmitter,ObiRope, etc) you can just do:
Code:
if (actor is ObiCloth)
//stuff A
else if (actor is ObiRope)
//stuff B
Reply
#3
(06-11-2019, 06:48 PM)josemendez Wrote: Hi,

You can easily retrieve which actor a particle belongs to. See "Retrieving the actor involved in a contact" in:
http://obi.virtualmethodstudio.com/tutor...sions.html

once you have the ObiActor (which is the base class for ObiCloth,ObiEmitter,ObiRope, etc) you can just do:
Code:
if (actor is ObiCloth)
//stuff A
else if (actor is ObiRope)
//stuff B

Again I just didn't observe the tutorials correctly. Thanks!
Reply