Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by Matt-Downey · Aug 12, 2011 at 10:22 PM · javascriptphysicsjointhingejointspring

Hinge joints not reaching target position

I have a hinge that has the following settings:

Rigidbody:

Mass = 1 Ang Drag = 0 Constraints: frozen on all but Y-axis

Hinge Joint:

Spring = 1 Damper = 0.001 Target Position = 0

...

The problem being the hinge joint fluctuates around the target position yet does not stop at 0, but instead +- ~6 degrees. Turning up the spring helps, but fails aesthetically.

Also, in physics I turned sleep angular velocity to zero, which did not help.

I also tried switching the damper to 0 and angular drag to 0.05 (the default), which worked no better.

I wanted to script the hinge myself until I read changing a rigidbody's angular velocity can yield unrealistic results.

[edit:]

Initially, I planned not to share my solution script, but after having to rewrite it, I decided to share it. This script is meant for a western style saloon door, which reacts to the player's movement. Increasing the spring in the HingeJoint and the script will make the door swing faster (and vice-versa) and increasing the damper will make it slow down faster. (I put damper at .1 and spring at 1 for a nice slow western feel). Furthermore, the mass of the player should be at least a magnitude of 3 (ie 1000x) greater in order for the door to perform optimally without getting in the way of gameplay.

 #pragma strict
 
 //next 3 are cached variables to increase performance
 var Trans : Transform;
 var Rigid : Rigidbody;
 var Hing : HingeJoint;
 
 //resting position in Eulers.y for the (saloon) door
 //ie where it is initially placed in the scene, called at start
 var rest : float;
 rest = Trans.eulerAngles.y;
 
 function Update ()
     {
     //this line makes sure we aren't checking when the door is at rest (optimization)
     if(Hing.spring.spring < 2)
         {
         //when the door is barely moving
         if(Mathf.Approximately(0,Rigid.angularVelocity.y))
             {
             //make the door swing faster, also stops sleep
             //(we don't necessarily want the door to sleep)
             Hing.spring.spring += Time.deltaTime;
             //if the door is approximately at resting position
             if(Mathf.Approximately(rest,Trans.eulerAngles.y))
                 {
                 //make the door stop all angular velocity
                 Rigid.angularVelocity.y = 0;
                 //manually place the door at the resting position
                 Trans.eulerAngles.y = rest;
                 //manually force the door to sleep
                 Rigid.Sleep();
                 }
             }
         }
     }
 
 function OnCollisionEnter ()
     {
     //THIS IS IMPORTANT
     //if this weren't here, the door spring would increment to infinity
     //making it swing super fast in the future, compounded each time the door is hit
     //AND continue to reach approximately plus or minus 6 degrees, not perfect equilibrium position
     Hing.spring.spring = 1;
     }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Melanina · Jun 14, 2013 at 10:37 AM

I have the similar problem, because i use too small scale in my project ( unity have finite accuracy ) just try put your object to another empty object and rise him scale to see difference. I hope someone know how to change this defect without scale manipulation.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to use Hinge Joints correctly inside a parent? 1 Answer

Why are my hinge joints inaccurate? 1 Answer

How to Recreate the Old Classic Snake with Hinged Joints 2 Answers

Configurable Joint chain with no spring/stretch? 2 Answers

How to add friction to Unity HingeJoint? 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