Search Unity

How can i achieve stiff fixed joints

Discussion in 'Physics for ECS' started by davvjs, Jul 31, 2020.

  1. davvjs

    davvjs

    Joined:
    Nov 13, 2016
    Posts:
    11
    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.


    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)



    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.
     
    Last edited: Jul 31, 2020
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Stiff fixed joints plus some more joints in the pairs of planks should be enough for you. They will also give you the option of disabling collision between pairs of planks. Now there will be wobbliness for sure, since the solver is iterative and can't find a perfect solution, but it shouldn't be too much.

    Now back to your example with collision filters, I really don't see why this system "explodes", setting the correct collision filter group should disable collisions between themselves and only increase stability. Can you please make sure that you've set BelongsTo = SomeValue and CollidesWith = ~SomeValue on all of the planks? Because I would expect that to be enough.
     
  3. LongAndHappy

    LongAndHappy

    Joined:
    May 10, 2019
    Posts:
    6
    I've found that switching from Unity Physics to Havok Physics increases the rigidity/stiffness of fixed joints
     
    petarmHavok likes this.