• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by prak · May 08, 2013 at 04:04 AM · jointsjoint

How to get Joint connectedBody OnJointBreak

I have multiple joints connected to a group of objects. If a joint breaks I want the original object and the connected object to respond. The method OnJointBreak doesn't give me any indication of the Joint connectedBody. How can I find the body that was connected?

Why the heck would they only give break Force!? Please help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by prak · May 09, 2013 at 04:07 PM

I created a work around that is not what i want, but until someone can suggest something better this is what i did.

created an array of connections

 //joints
 public ArrayList<Part> connections;

then as i create joints i add them to both parts, the original and the connectedBody.

 parts[i, j].connections.Add(parts[i + 1, j]);
 parts[i + 1, j].connections.Add(parts[i, j]);

then when a joint breaks i flip a flag and wait:

 void OnJointBreak(float breakForce) {
     JointBroken = true;
 }

in the next update (when the joint has been destroyed) I the go looking for the missing joint:

 if (JointBroken) {
     Ship.EvaluateJointBreak(this);
     JointBroken = false;
 }

then i can find and act on missing joint

     public static void EvaluateJointBreak(Part part) {
         foreach (Part sp in part.connections) {
             if (sp == null) 
                 continue;
             Joint j = findJoint(part,sp);
             if (j == null) {
                 //missing joint
             }
         }
     }    
 
     public static Joint findJoint(Part part1, Part part2) {
         foreach (Joint j in part1.GetComponents<Joint>()) {
             Part temp = j.connectedBody.GetComponent<Part>();
             if (temp == part2) {
                 return j;
             }
         }
         foreach (Joint j in part2.GetComponents<Joint>()) {
             Part temp = j.connectedBody.GetComponent<Part>();
             if (temp == part1) {
                 return j;
             }
         }
         
         return null;
     }

There you go.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mrlinds · Mar 23, 2018 at 08:18 PM

I recently ran into this issue, but found a better solution, likely because of Unity updates. In Unity 2018 you can now check joint.currentForce. Not sure when that was added

 private void OnJointBreak(float breakForce) {
         for ( int i = 0; i < joints.Count; i++ ) {//have list of joints
             ConfigurableJoint joint = joints[i];
             if (breakForce != joint.currentForce.magnitude ) {
                 continue;
             }
             RemoveJoint(joint); //do joint cleanup
             break;
         }
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LorenzoValente · Nov 30, 2020 at 11:20 AM 0
Share

It is not a good idea to check inequality between two floats using the != operator. Floats may have precision errors. You should use $$anonymous$$athf.Approximately

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Tie objects together 5 Answers

2d ragdoll joint connection. 0 Answers

How to set a different linear limit for each axis on a configurable joint 0 Answers

Drive modes not showing in Inspector for Configurable Joint? 1 Answer

How to change the length of the object with configurable joint attached 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges