Hi everyone,
lets say i have two boxcollider intersecting each other (including any possible rotation) - how could i retrieve the center of the intersecting area?
Thank you so much! ![]()

Hi everyone,
lets say i have two boxcollider intersecting each other (including any possible rotation) - how could i retrieve the center of the intersecting area?
Thank you so much! ![]()

I am not sure if it will work, but I think if you have the contact points
and caculate the centroid of these points you will get the center
You may try Physics.ComputePenetration. Given two intersecting colliders this function computes the minimal translation required to separate them apart. The result is a distance and a direction vector. Maybe the half-way the distance is an useful point in your case.
Both answers are good, unfortunately i cannot use contacts because im not using the OnCollision events, but otherwise that would be useful. I think ComputePenetration is what i need ![]()
I would suggest to use raw math to solve, especially for box colliders
If it will be actual for someone
Bounds bounds1 = new Bounds(new Vector3(0, 0, 0), new Vector3(2, 2, 2));
Bounds bounds2 = new Bounds(new Vector3(1, 1, 1), new Vector3(3, 3, 3));
Bounds intersectionBounds = new Bounds();
if (bounds1.Intersects(bounds2))
{
intersectionBounds.SetMinMax(
Vector3.Max(bounds1.min, bounds2.min),
Vector3.Min(bounds1.max, bounds2.max)
);
}
Debug.Log("New Bounding Box Size: " + intersectionBounds.size);
It is, thank you very much, exactly what I was looking for after chat GPT wrote some shitty code ![]()