I have two colliders that are nested. Each of these has its own tag. When the colliders touch the rope, only the outermost, that is, the first contact with the rope, is seen. How do I solve this?
Quote:void Solver_OnCollision(object sender, 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:
ObiColliderBase col = world.colliderHandles[contact.bodyB].owner; if (col != null) { if (col.CompareTag("saw")) TearRope(col, contact); else if (col.CompareTag("nearMiss")) { DamageRope(col, contact); }
22-11-2021, 01:55 PM (This post was last modified: 22-11-2021, 01:58 PM by josemendez.)
(22-11-2021, 01:51 PM)greyhawk Wrote: Greetings,
I have two colliders that are nested. Each of these has its own tag. When the colliders touch the rope, only the outermost, that is, the first contact with the rope, is seen. How do I solve this?
Hi there!
If by "nested" colliders you mean one collider completely inside another, that doesn't make any sense (not in Obi, not in Unity, not in any other physics engine). Only the outermost collider will report contacts agains the rope, simply because the rope can't ever touch the inner one.
What is your goal? maybe I can help you find some other way to do what you want? Would it help for the outer collider to be a trigger instead?
22-11-2021, 02:15 PM (This post was last modified: 22-11-2021, 02:16 PM by greyhawk.)
(22-11-2021, 01:55 PM)josemendez Wrote: Hi there!
If by "nested" colliders you mean one collider completely inside another, that doesn't make any sense (not in Obi, not in Unity, not in any other physics engine). Only the outermost collider will report contacts agains the rope, simply because the rope can't ever touch the inner one.
What is your goal? maybe I can help you find some other way to do what you want? Would it help for the outer collider to be a trigger instead?
Both colliders are already triggers. Let me explain the situation with a picture. I have an object like the image below. Collider with nearMiss tag is in the child of our main object. The first contact with the rope is nearMiss, but when it comes to the sawZone part, I break my rope.
(22-11-2021, 02:15 PM)greyhawk Wrote: Both colliders are already triggers. Let me explain the situation with a picture. I have an object like the image below. Collider with nearMiss tag is in the child of our main object. The first contact with the rope is nearMiss, but when it comes to the sawZone part, I break my rope.
Oh, ok! If they're both triggers, it should work fine. Do both have a ObiCollider component?
(22-11-2021, 02:18 PM)josemendez Wrote: Oh, ok! If they're both triggers, it should work fine. Do both have a ObiCollider component?
Yes, both have obicollider component. The weird thing is that when i turn off the nearMiss collider it can see the saw collider. But when the two are together, rope only sees the outermost collider, which is the first contact.
22-11-2021, 02:39 PM (This post was last modified: 22-11-2021, 02:43 PM by josemendez.)
(22-11-2021, 02:29 PM)greyhawk Wrote: Yes, both have obicollider component. The weird thing is that when i turn off the nearMiss collider it can see the saw collider. But when the two are together, rope only sees the outermost collider, which is the first contact.
I'm unable to reproduce this.
Used the RopeShowcase sample scene as a basis, made all 3 objects at the front into triggers and nested them. All 3 are detected and change colors properly:
This is the code being used, which is very similar to yours. Note I do check for contact distance and discard speculative contacts, yours doesn't (not sure if this is intentional). Also instead of filtering by tag, I just placed a component on the objects and call a method on it:
Code:
Oni.Contact[] contacts = e.contacts.Data;
for(int i = 0; i < e.contacts.Count; ++i)
{
Oni.Contact c = contacts[i];
// make sure this is an actual contact:
if (c.distance < 0.01f)
{
// get the collider:
var col = colliderWorld.colliderHandles[c.bodyB].owner;
if (col != null)
{
// make it blink:
Blinker blinker = col.GetComponent<Blinker>();
if (blinker)
blinker.Blink();
}
}
}
Without more info I don't think I can help you further. The code is really simple so it should work. Are there other components/scripts in your scene which might be interferring?
(22-11-2021, 02:39 PM)josemendez Wrote: I'm unable to reproduce this.
Used the RopeShowcase sample scene as a basis, made all 3 objects at the front into triggers and nested them. All 3 are detected and change colors properly:
This is the code being used, which is very similar to yours. Note I do check for contact distance and discard speculative contacts, yours doesn't (not sure if this is intentional). Also instead of filtering by tag, I just placed a component on the objects and call a method on it:
Code:
Oni.Contact[] contacts = e.contacts.Data;
for(int i = 0; i < e.contacts.Count; ++i)
{
Oni.Contact c = contacts[i];
// make sure this is an actual contact:
if (c.distance < 0.01f)
{
// get the collider:
var col = colliderWorld.colliderHandles[c.bodyB].owner;
if (col != null)
{
// make it blink:
Blinker blinker = col.GetComponent<Blinker>();
if (blinker)
blinker.Blink();
}
}
}
Without more info I don't think I can help you further. The code is really simple so it should work. Are there other components/scripts in your scene which might be interferring?