Hello again! I’ve terrible luck in getting my questions answered, since i ask for such damned difficult things, but let’s give this a shot again.
I need to find a way on how to only take into account a singular gameobject’s colliders’ bounds, in a scenario where there are children that have colliders too.
I have a script, which does some physics stuff (would take focus away from question to explain further) to an object with a rigidbody attached, based on Collider.bounds.
The issue i have, is that if i happen to have a child with colliders attached to it, it takes into account the child’s colliders too. The usual fix would be to plant a kinematic rigidbody onto this child object, but since i’m already fooling around with physics, i can’t do that, since it affects how the object behaves.
It also takes into account any triggers, for that matter, which is strange, but not actually an issue at this point.
I have a workaround, however, but it is not optimal at all, as i’d need to do this to every last collider i want manually, and not all shapes work fine with it:
public BoxCollider CollFrame; //Set in editor
void Start() {
Bounds b;
if (CollFrame == null)
{
b = collider.bounds;
}
else
{
b = CollFrame.bounds; //Must set this, otherwise it gets grumpy.
b.center = CollFrame.center;
b.extents = CollFrame.size / 2;
b.max = CollFrame.center + b.extents;
b.min = CollFrame.center - b.extents;
b.SetMinMax(b.min, b.max); //This seems to be necessary
b.size = CollFrame.size;
}
foo(b);
}
Does anyone have a nice way of getting around the usual method Collider.Bounds work, so that it can ignore its children? The problem is that my implementation specifically uses the Collider.Bounds, it doesn’t use OnTrigger or OnCollision events, so usual fixes don’t apply.