0
\$\begingroup\$

I'm working in unity and I have the following problem : Suppose you have an object that's very similar to say the intersection of say the corner of a cube and a ball, and you want a nice collider for this object.

First option is to simply use the mesh collider option - but this is apparently not very efficient, and if for example the sphere is very smooth, there might be a lot of polygons and that could be a problem.

Second, you could just fill the object with various simple colliders.

However, both of the above options seem unnecessarily complicated - it would seem natural to me to somehow work with both colliders - the sphere collider and the cube collider. To determine if the object is touching something, the requirement is that both the cube and sphere collider are touching something, not just one of them.

I don't know how the actual collision checks work, but I would expect that say in the second option I wrote above (placing a few small colliders inside the object), a collision check sees if any of the colliders is touching a collider of some other object - so there is an option for "union" type of collision check (see if any of the colliders are touching something). Similarly, I would expect there would be an option of checking whether both the colliders are touching something, but I'm not aware of it.

Either way, I would appreciate ideas on how to implement a good collider for this problem, and whether there's a way to implement it by the way I described, using the "intersection" of two colliders.

\$\endgroup\$
  • \$\begingroup\$ I'm not aware of any option in Unity's PhysX or Box2D engines for the kind of intersection collider you're describing, but we might be able to "fake" it in some circumstances. Does this object move? How many similar objects are there in your scene? What kinds of objects / queries need to interact with it? \$\endgroup\$ – DMGregory Apr 16 at 18:14
  • \$\begingroup\$ @DMGregory I was thinking of doing a mesh-slicing feature ( for fun, and as a learning project) . Ideally, it would work on moving objects, for all sorts of slice angles, and all sorts of objects. While I see possible ways of doing this, it just feels like a bit of waste, when I could simply create say a large box for each side of the slicing plane, and then use the "intersection" collider I described above, together with the original collider of the object that's being sliced. \$\endgroup\$ – John P Apr 17 at 0:39
  • \$\begingroup\$ Besides that, I could fill the object with lots of simple small colliders, and when a slice is made, only use the colliders in the respective half above/below the slice plane. Another option would be to figure out some sort of approach to "fill" up the newly created two meshes with completely new colliders, perhaps ignoring the colliders in the original mesh. If I know how the original mesh looks, it should be possible to do this somewhat efficiently. Lastly, I could simply use the mesh collider option, maybe applied on a slice of some sort of low-poly approximation of the original mesh. \$\endgroup\$ – John P Apr 17 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.