• 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
Question by Skyblade · Jun 12, 2017 at 08:53 PM · physicsjointsjointhingejointphysx

How to add friction to Unity HingeJoint?

I attach a rigidbody to a HingeJoint in Unity.

It's attached no at the the center of an anchor of a joint.

To stop it from falling I set Use Motor = true, Target Velocity = 0 and apply some force to the motor.

However, this does not help, see video:

http://g.recordit.co/JJ0cmfT1Mb.gif

Here is the sample project: https://drive.google.com/open?id=0B8QGeF3SuAgTNnozX05wTVJGZHc

Screen from sample project to reproduce the issue (there is no code): alt text

How can I apply a friction to a joint to stop rigidbody from moving?

Note: setting spring with damper or applying a limit is not an option for me, because I need to rotate the rigidbody correctly when I apply enough torque (force) to a motor.
If I switch damper/limit on and off, the rigidbody will move faster when it is rotated in a direction of falling and slower when it is rotated in opposite direction.

Comment
hyouuu

People who like this

1 Show 0
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

Answer by ZiadJ · Feb 22, 2018 at 05:19 PM

I found a similar question here and a seemingly correct way to achieve it: https://stackoverflow.com/questions/44497538/how-to-add-friction-to-unity-hingejoint

 using UnityEngine;
 
 public class JointFriction : MonoBehaviour
 {
     [Tooltip("mulitiplier for the angular velocity for the torque to apply.")]
     public float Friction = 0.4f;
 
     private HingeJoint _hinge;
     private Rigidbody _thisBody;
     private Rigidbody _connectedBody;
     private Vector3 _axis;  //local space
 
     // Use this for initialization
     void Start()
     {
         _hinge = GetComponent<HingeJoint>();
         _connectedBody = _hinge.connectedBody;
         _axis = _hinge.axis;
 
         _thisBody = GetComponent<Rigidbody>();
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         var angularV = _hinge.velocity;
         //Debug.Log("angularV " + angularV);
         var worldAxis = transform.TransformVector(_axis);
         var worldTorque = Friction * angularV * worldAxis;
 
         _thisBody.AddTorque(-worldTorque);
         _connectedBody.AddTorque(worldTorque);
     }
 }

Comment

People who like this

0 Show 0 · 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.

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

105 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 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 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 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 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

Hinge Joint On Little Noodle Carton (with pic) 1 Answer

How target rotation and target angular velocity work in configurable joint ? 1 Answer

How to get configurable joint to observe limits? 1 Answer

Is there a Distance Constraint 3D or Distance Joint 3D in Unity? 2 Answers

How to create a freely swinging "rope" of modifiable size between two rigid bodies? 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