In the previous version of my engine i used CompoundColliders that i modified dynamicly when the user was building. However this made the codebase a lot more complicated and its something i would like to avoid in my current rewrite if possible.
I have tried using fixed joints but I have a hard time tweaking the spring parameters to get a stiff behavior.*
Here I have four bodies jointed to a center body using fixed joints. I also have a joint with a 2D constraint on all 5 bodies. The joints have collisionenabled=false, but i don’t have any filter on the colliders, which means the outer 4 bodies are probably colliding with eachother.
serpentinereliablegavial
If I put all bodies under a filter that doesn’t collide with itself I get this weird behaviour instead:
(Tried both groupIndex=-1 and CollidesWith=~BelongsTo, they give the same behaviour)
calculatingtameglassfrog
So basically, I’m getting fake stability by having intersecting bodies with collision enabled, which doesn’t feel right. I shouldn’t need the bodies to collide since I never want the joint bodies to move in respect to each-another.
TLDR:
I need help with what approach I can use that avoids CompoundColliders but gives me the closest behavior in terms of the physics simulation. I know I am essentially asking for multiple bodies to behave as one, but I would really like them to be separate entities.
Some ideas:
- At all times ensuring there is a joint between every possible body-pair in the “compound” might increase stability?
- Using some sort of parent-child relationship on the entities and getting them to behave together with physics
- Some approach that lets me use CompoundColliders + have an entity for each sub-body that is rendered at the appropriate location by the MeshRenderSystemV2
I can be ok with some level of wobbliness on the fixed joints. I am making a game after all, but the current levels are just to extreme. The behaviour should exhibit wooden planks jointed together with nails.
Reasons i want to avoid compound colliders
-
I often want to treat the parts making up the compund as separate entities in my behavior systems
-
It forces me to rely on a self made “CompundColliderRenderSystem” (which unfortunately can only handle one material per compound collider at the moment)
-
Every time i want to do something with the entity i have to check if it has a compund collider and check which “child collider” is relevant at the moment.
-
I probably want breakable joints in the future.
-
Either as a future implementation in the physics package, or something i implement myself.
* Only documentation I have found for these parameters are comments in the code. Based on the comments I can’t even derive whether the values should be high or low.