• 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
2
Question by MadMenyo · Mar 13, 2015 at 12:00 PM · c#physicshingejoint

Hingejoint not responding on script

I have a hingejoint setup. When I press a key I can see the number at the "target position" in the inspector change but the mesh it is attached to does not move. But when I type in a random number at "target position" the mesh does move.

The script attached is very basic:

 public float defaultPosition = 0.0f;
     public float targetPosition = 50.0f;
     public float springStrength = 100.0f;
     public float springDamper = 1.0f;

     private JointSpring spring;
     
     void Awake ()
     {
         GetComponent<HingeJoint>().useSpring = true;
         spring = new JointSpring();
         spring.spring = springStrength;
         spring.damper = springDamper;
     }
     
     void Update ()
     {            
         if (Input.GetKeyDown (KeyCode.D)) 
         {
             Debug.Log ("D pressed");
             spring.targetPosition = targetPosition;
         }
         else
             spring.targetPosition = defaultPosition;
         
         GetComponent<HingeJoint>().spring = spring;
     }

-edit- The problem is stranger then I thought. I removed the script component, added it again end it worked. But once I change a public variable in the inspector it breaks. Besides that if I re-attach the script component it does not always work, sometimes I have to re-attach it several times.

Comment
Add comment · Show 5
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 MadMenyo · Mar 13, 2015 at 04:39 PM 0
Share

I made some two video's: https://www.youtube.com/watch?v=hIPkPyYqAcY and https://www.youtube.com/watch?v=D1bH0Dkl7p4 showing the issue. I basically have to set the default position to -10 for it to work. But als a higher force or damper break things. It even came to a point that when I clicked out of the game window and back it broke.

avatar image MadMenyo · Mar 13, 2015 at 04:40 PM 0
Share

Here is the project: http://forum.unity3d.com/attachments/pinball-zip.130468/

Basic, simple but not working...

avatar image stephancom · Apr 06, 2015 at 03:01 AM 0
Share

I seem to be having this same problem, in Unity 5.0

avatar image MadMenyo · Apr 07, 2015 at 10:54 AM 0
Share

@stephancom I guess this really is a bug then.

avatar image stephancom · Apr 09, 2015 at 02:06 AM 0
Share

I filed a bug report and made a github repo illustrating it...

https://github.com/stephancom/unity-hinge-bug

but as I play with it, I'm wondering if this is really a bug, or just a misunderstanding of how it works? Because in my sample project, it seems like it works but the hinge needs "a little poke" to get moving.

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HarshadK · Apr 07, 2015 at 11:03 AM

Instead of creating a new Spring instance here, you need to get the current spring from the HingeJoint. Something like:

  void Awake ()
  {
      GetComponent<HingeJoint>().useSpring = true;
      // Get the spring from the HingeJoing
      spring = GetComponent<HingeJoint>().spring;
      spring.spring = springStrength;
      spring.damper = springDamper;
  }
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 MadMenyo · Apr 07, 2015 at 12:51 PM 0
Share

Nope still the same result: nothing when I use the "D" key even with get$$anonymous$$ey ins$$anonymous$$d of get$$anonymous$$eyDown. And the damn thing is moving when I change the value manually in the inspector while running.

avatar image
0

Answer by stephancom · Apr 09, 2015 at 04:31 AM

This appears to be a bug, I've created a github repository that illustrates the issue

https://github.com/stephancom/unity-hinge-bug

A very simple scene, when you walk into the collider, the spring should open the door, and it does not - the values change in the project, but there is no movement. Manually changing the values while it is running works.

How do I file a bug report, and do they pay bounties?

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 kinggryan · May 12, 2015 at 09:48 AM

I've also encountered this and devised a workaround. I'm not sure, but it seems like changing the constraints of a joint do not cause the physics engine to calculate a solution for the scene. By "prodding" the object whose joint's constraints have been changed, you can force a solution. For me, after changing the constraints of a joint, I called AddForce(Vector3.zero) on the object's rigidbody. This caused the new constraints to be enforced.

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 MarshCZA · Nov 06, 2018 at 02:00 PM

I've had the same problem and fixed it by calling

GetComponent().WakeUp();

After you change the spring values.

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

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.

Follow this Question

Answers Answers and Comments

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Set a HingeJoint's Target Position to point toward an object? 1 Answer

Multiple Cars not working 1 Answer

2d game platform physics 1 Answer

How to change CC script to Rigidbody script 1 Answer


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