- Home /
HingeJoint2D.GetReactionForce not working
Since the 2D joints in unity do not seem to have a break force/torque built in, I wanted to write it in a script myself by reading the joints reaction force in the following code:
 var breakForce : float = 100;
 private var jointForce : float;
 
 function Start() {
 var joint = gameObject.AddComponent(HingeJoint2D);
 }
 
 function FixedUpdate() {
     jointForce=joint.GetReactionForce;
     if (jointForce>breakForce) {
         Destroy(joint);
     }
 }
The documentation says that HingeJoint2D.GetReactionForce should be possible: http://docs.unity3d.com/ScriptReference/HingeJoint2D.GetReactionForce.html
However unity tells me: 'GetReactionForce' is not a member of 'UnityEngine.HingeJoint2D'. This made me very confused. I hope someone can help me!
Answer by MinsukCha · Jun 09, 2014 at 08:56 AM
Your code should be something like this:
 var breakForce : float = 100;
 private var jointForce : Vector2;
 var joint : HingeJoint2D;
  
 function Start() {
     joint = gameObject.AddComponent(HingeJoint2D);
 }
  
 function FixedUpdate() {
     jointForce = joint.GetReactionForce ( Time.deltaTime );
     if (jointForce.magnitude > breakForce) {
        Destroy(joint);
     }
 }
GetReactionForce returns Vector2 type. You can't convert to float directly. And declare 'joint' as a HingeJoint2D' type. You might compare jointforce's magnitude with the variable 'breakForce'.
Hey thanks a lot for the reply! Unity now gives me the following error, again I am clueless...
 $$anonymous$$issing$$anonymous$$ethodException: UnityEngine.HingeJoint2D.GetReactionForce
 Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.ProduceExtensionDispatcher ()
 Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.Create ()
 Boo.Lang.Runtime.RuntimeServices.DoCreate$$anonymous$$ethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
 Boo.Lang.Runtime.RuntimeServices.Create$$anonymous$$ethodDispatcher (System.Object target, System.String name, System.Object[] args)
What version of Unity are you using? GetReactionForce is available only from v.4.5. Please check it out and upgrade Unity if necessary. Thanks~.
Ah that must be it. I am still using 4.3 at the moment. Thanks!
Your answer
 
 
             Follow this Question
Related Questions
Wheel Friction Curve in 2d 0 Answers
New Pointer Effector 2D Help 0 Answers
Make a hinge joint stay firmly in place 4 Answers
Unity HingeJoint2D issues when Flipping ( Negative Scaling ) 1 Answer
Gravity Direction Change 2D 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                