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. Dismiss Notice

I need to know which joint has broken

Discussion in 'Physics' started by tonyoakden2, Aug 28, 2017.

  1. tonyoakden2

    tonyoakden2

    Joined:
    Oct 14, 2016
    Posts:
    13
    I create a ragdoll, procedurally, using capsules and configurable joints. The joints can break if there is an impact above a certain force. I'm setting breakForce in the joints to enable that. I'm using the built in unity function "OnJointBreak(float breakForce); to trap the breaking and create various effects if it happens, and that works OK, but each capsule has two joints and this function doesn't tell me which of the two joints has broken. For my code to work properly I need to know this. I read the physX documentation and the callback that physX generates on a joint break does contain this information. Is there someway of getting it in Unity?

    regards,

    Tony
     
  2. guillermoi

    guillermoi

    Joined:
    Sep 20, 2012
    Posts:
    27
    Hey

    I came across this the other day and I don't think there is a callback that tells you exactly which one was it (you get the callbacks for both joints in the script in the capsule).

    But you can create a small component that you add on each joint and then tells the capsule script about the event and the information that you want

    Code (CSharp):
    1. //JointEvent.cs
    2.  
    3. //Optioan A
    4. public Action<float> OnJointBreak;
    5.  
    6. //Option B
    7. public Action<float,Joint> OnJointBreak;
    8.  
    9.  
    and then

    Code (CSharp):
    1. //CapsuleScripts.cs
    2.  
    3. void Start(){
    4.     ...
    5.     leftJointEvent = leftJoint.AddComponent<JointEvent>();
    6.     leftJointEvent.OnJointBreak +=OnLeftJointBreak;
    7.     ...
    8. }
    9.  
    10. //Option A
    11. void OnLeftJointBreak(float breakForce){
    12.     ...
    13. }
    14.  
    15. //Option B
    16. void OnLeftJointBreak(float breakForce, Joint brokenJoint){
    17.     ...
    18. }
    19.  
     
  3. touzov

    touzov

    Joined:
    Feb 19, 2017
    Posts:
    4
    I am not certain how you call leftJoint.AddComponent. The method is only available on GameObject, so adding a component to the joint is hardly possible.