question about boxcollider(axis aligned --> oriented alig

I’m noticing that the default box collider is using a AABB( Axis-aligned Bounding Box),
however, this kind of box collider does not work well on the raycast detection on a not axis aligned cube, such as 40 degrees rotating to the x Axis.
This can be solved by using a OBB(Oriented Bounding Box). It seems that many programs use OBB for colliders detection but only AABB to camera culling.
Is unity3d possible to create a OBB collider component? I just can’t find it, or someone has any scripts on that?
I know that mesh collider can work on that, however, it seems too expensive comparing to a OBB box collider.

anyone knows about this?

I’d like to know this also.

The box collider rotates with the game object. Create a normal cube, rotate it 40 degrees, and the collider is also rotated. Unless I’m missing something here.

–Eric

thanks for the reply. However, my cube’s vertices is provided by me as a mesh. In another word, the rotation of the transform is still identity, but the vertices position iteself has already encapsulate the rotation.

The mesh is nearly a cube, not a default cube gameobject of unity3d editor. So I just provide the vertices position by myself, however, if it is not alighned with any axis, it seems that the box collider is not so accurate. The mesh collider is very accurate, however, it’s so expensive. Do I need an oriented aligned box collider instead of an axis aligned box collider.

I think this can be computed by something like PCA, however, I want to know that if unity3d has already have this or someone else has made something like this

any suggestion?

I still don’t understand the problem. A game object with a box collider can be rotated any way you like, so you can make it match up with a mesh no problem.

–Eric

If I understand correctly, you are asking if the box collider can be rotated independently, rather than being aligned with the object’s local XYZ axes? You can change the position and size of the box collider, but unfortunately not the rotation. If you are providing the cube’s vertices yourself, would it be possible to make the cube axis-aligned? I’m thinking you could put the cube object (with its box collider) inside a parent object - that way, you could rotate the cube and collider however you want relative to the parent’s axes.

I would also like the ability to rotate a box collider independently, for the exact same reason you need to move it or scale it. I have a street model a curved street model. The houses are all on a curve. If I could rotate the box collider, I could align with the house.

The only other option now it to rotate them all to square with the world axis, add the colliders, and rotate them back.

yes, exactly.

Let me make it clearer to understand, I have a non-regular model (not a regular one such as a cube), and all the vertics come from 3dsmax or maya, The model is not aligned to any axis, and the box collider can only provide accurate ray intersection detection on axis aligned model(it’s bounding box is aligned to any axis).

So, is any oriented box collider available whose aligning is calculated by finding the main axis of object using PCA? Is there any available in unity3d or anybody else have done this before? thanks!

Just to clarify… the object with the collider doesn’t necessarily have to be the same object that has the mesh. You might be able to achieve what you want by creating an empty GameObject (ie, GameObject > Create Empty), adding a box collider to it and then making this object a child of your mesh. You could change the orientation of the child object, and that would effectively allow you to rotate the box collider without changing the position of the mesh. It is probably not as neat a solution as you would like, but maybe it would solve your problem.

In case it helps anyone: In my game I could overcome this by instantiating a prefab at the location of my beacons which had a aabb, rotate the new to point the way I wanted it, adding a box collider and destroying the old beacon.

I think your method can solve the prolbem, but the OBB should also be computed to get the rotation angles, so nobody has ever computed OBB by unity?

From what I’ve read so far, it seems that principal component analysis doesn’t reliably give a good OBB, although it usually makes a reasonable attempt. There are a few promising algorithms for OBB that I am investigating - I’ll let you know if I find a good solution to this problem.

thanks, that’s great!

andeeee, any progress on this issue? I have found this thread after running into a very similar issue as described by azuretttc and brendang. I’m sure you are aware, a common method to determine the minimum-volume/oriented bounding box is the O’Rourke “3-dimensional rotating calipers technique”. There seems to be a C++ implementation HERE in the “Wm4ContBox3.*” files. However, I am a little rusty on the math there and this it could be non-trivial (for me) to port to C#.
This method would obviously be computationally heavy, but my use would be a only be a one-time event at start-up.

However, I do see the alternate approach that’s been suggested, using an empty GameObject with box-collider rotated to the parent object mesh. Could this be done procedurally? What would be a method to align/scale a bounding box to enclose an arbitrarily-oriented object?

I’m thinking of one possible approach…

  • start by adding a temporary mesh-collider to the target mesh
  • create the empty child gameobject with box-collider, based off the normal AABB of the target mesh
  • do iterations of rotate down-scale this child box-collider until collision is detected with the target mesh
  • find the case of minimum box-collider volume/size.

(for my applicatoin, I’m assuming to only need to rotate in the Y axis)

No progress, unfortunately - I did look into this, but it became clear that it would take more time than I can really devote to it. There’s actually a bit more to it than converting the C++ code to C#. The algorithm is reasonably straightforward, but it works on the convex hull of the mesh, so you also need a convex hull algorithm before you start.

I’ll take another look at this because it might be a quicker job with some existing code to work from, but I’m afraid I can’t promise anything.