Question Update. I have added a screenshot of a compound collider solution. I do realise you can create child game objects and rotate the colliders. Though, for what I want to do, colliders like this works. Improvements would be a bonus, but I have over 500 objects that need this solution as shown by example by the stone portion below. Does anyone have a good starting point for the code do automate what I have done manually here? I am ok with the coding in general, but I lost with unities space constructs, particularly when you are dealing with meshes, worldspace local space and so on. Even if someone had the code for placing one box collider within the space of the vertices, that would help me out for the rest.
Note1<<< What is important is that the colliders fill key points of the outside, or edges, or corners. The middle does not matter for the size the other colliding objects. Nothing collides there. There can be gaps. As per the screenshot.
Note2<<<< It is not bad in my game, if portions of the edges are not filled with colliders. So long as the main shape is filled close to the edge, it looks realistic, in physics to the eye. I have tested this.
Mesh colliders causes lag when activating object. Their generation. Impossible. can’t use.
Box colliders fit badly, and messes up all my physics calculations.
This is the scenario, Im sure you get what I mean. I got so many problems in my physics because of this. Like im stuck achieving my goals.
I need the colliders somewhat accurate, because if not, unity treats it when you set iskinematic to false, like an explosion if your stuff overlaps. It becomes very messy. And you get unrealistic results.
Thus I have objects close to each other, irregular shaped stones etc, that overlap colliders because I have to use box. Thus im caught in this pyshics trap, of not being able to set them as alive physically, unless at the last moment.
I feel greatly let down, by the collider issue here of unity
Tell me, what have you superstars done to get around this issue?
There’s nothing inherently wrong with Unity’s physics system. It’s the tried and proven PhysX by Nvidia, which is used by thousands of commercial products.
Maybe you are trying to achieve things not possible or you are missing a better way if implementing what you want. What is your specific goal?
Unity has two pages on physics best practices, here and here.
But most of the time it’s simply a matter of creating reasonable scenes. For example: Mesh colliders are always expensive. You don’t want to use many of those. Enabling and disabling colliders should never be done unless the GameObject also contains a rigidbody. If you enable a collider on an object with a rigidbody, the entire physics world must be recalculated. Hence, moving or dynamic colliders must also have a rigidbody. All GameObject that don’t move should be marked as static, so Unity can perform optimization, knowing they will not move. It all depends on your target platform, but you want only a few rigidbodies, but you can have many more static colliders. On mobile, probably 1 - 10 active rigidbodies, on standalone maybe 50 - 100, something along that line. Mesh colliders should only be used sparingly and best for static geometry. Characters commonly use capsule and circles to approximate their collision, which is good enough for AAA-games. If you are making a pixel-perfect 2D platformer you may want to switch to per-pixel collision checking, which you implement yourself or buy as a 3rd party product.
Coming back to your example of irregular shaped stones. I wouldn’t recommend simulating a landslide of physically correct stones in a game. You need to approximate, either by using spheres/circles, which do work if you have say 20 circles rolling about, but they all need a rigidbody, remember.
If you have a collider set to isKinematic, then turn it on and experience an explosion, you’ve simply made a mistake placing your objects. You need to prevent them from overlapping in the first place. There’s also a lot of intricate settings like penetration depth, but that’s probably beyond the scope here. Most of the time its fine to just place objects correctly.
Set collision detection to Continuous instead of Discrete. That should help achieve accurate collisions.