Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get break force in advance of object breaking

Discussion in 'Physics' started by RakNet, Nov 24, 2017.

  1. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    313
    I'm making a building game where I place a bunch of objects in Kinematic mode, connected by FixedJoint. When the simulation starts I turn off kinematic mode and everything breaks apart. What I would like to do is find out the break forces before turning off kinematic mode, so I can set the FixedJoint break forces in code.

    What formula / code goes into the break force calculation?
     
  2. KeithKong

    KeithKong

    Joined:
    May 31, 2015
    Posts:
    73
    When you say "figure out the break forces" I'm assuming you mean "calculate the forces that will be applied by the structure once you turn physics on". That's going to be a complicated formula that essentially encompasses the entire implementation of PhysX forces and collisions.

    If you simply want to know what the joint break force value is compared against, I'm fairly certain it checks the relative velocity between the two jointed objects at the end of the fixed frame simulation, and converts from velocity to force using the mass of the object owning the joint. That, or it compares the joint solver force applied to the owner by the connected body per fixed frame directly.

    Functionally, you can just consider your projectiles (or other objects that will hit your structures) and decide around what velocity they should break stuff. Then convert from velocity to force using the objects mass
     
    Last edited: Nov 25, 2017
  3. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    313
    I saw this same question in multiple other forum posts and like this one they were all answered incorrectly, or not at all.

    I just randomly came across the solution while working on something else.

    Joint has a member currentForce and currentTorque. You can just set the breakTorque and breakForce values to infinity. Then check this against joint.currentForce.magnitude and joint.currentTorque.magnitude
     
    TooManyNames likes this.
  4. KeithKong

    KeithKong

    Joined:
    May 31, 2015
    Posts:
    73
    That's a good catch, I always forget they added currentForce and currentTorque. That being said, my answer stands on two points.

    1) The break force compares against the joint solver force combined with any external impact forces. Assuming you are checking at a time when no external forces are being applied, currentForce and currentTorque give you the resting joint solver force (you may need to investigate if the rigid body goes to sleep, and if those properties remain accurate when it's sleeping).

    2) Assuming all the possible issues in 1 can be resolved, you still need to consider the mass/speed of colliding objects to calculate a good additional force to add on top of currentForce and currentTorque. In the end you may end up having to just trial and error this part.