• 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 llermy · Aug 18, 2021 at 08:59 PM · hingejointtorque

Unable to AddTorque to a HingeJoint with spring force,Hinge joint with spring ignores AddTorque

Hi! I'm facing a very interesting problem. I have three connected hinge joints joined together to form the leg of a character. These hinge joints use the hinge joint spring option with spring parameter in the range of 50-240 and damping paramenter in the range of 1.5-6. All these hinge joints can only rotate around de z axis. And this works as expected. The problem is, when the spring option is activated I am not able to add any significant torque around the axis in FixedUpdate with a simple:

 GetComponent<Rigidbody>().AddTorque(axis * torque);

It does not matter the magnitude of the torque, it only rotates the hinge joint a tiny bit. If I debug the value of GetComponent<HingeJoint>().currentTorque, I can see the torque is really very low. If I deactive the spring option of the HingeJoint, the torque is added as expected. If I have a lower spring parameter, AddTorque seems to add more torque, but the HingeJoint is not as stiff as I require.

I've uploaded a video so you can check the problem with a minimal example: https://youtu.be/w1vxVBoZF6c


Is HingeJoint's spring force and AddTorque incompatible? If so, is there any way I can add proper torque to the joint?

[1]: https://youtu.be/w1vxVBoZF6c

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

Answer by llermy · Sep 17, 2021 at 07:38 AM

It seems the solution is actually quite simple. It is due to that only AddTorque is limited by Rigidbody.maxAngularVelocity, but not the resulting torque including the spring torque, so the applied torque could not overpower the spring. So making Rigidbody.maxAngularVelocity bigger solved the problem.

Comment
Add comment · Show 2 · 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 GamerLordMat · Sep 17, 2021 at 09:05 AM 0
Share

Sorry for being rude, but why do you even ask a question if you don't bother to read the provided answers carefully? Both sides waste their time.

if your max angular velocity is low (default 20) than even very high torque won't change your rotation much,

avatar image llermy GamerLordMat · Sep 17, 2021 at 09:22 AM 0
Share

Well, although you mentioned that part, the solution you have proposed does not solve the problem I state. When I was trying your solution and discussing it with you, you did not explain that Rigidbody.maxAngularVelocity only caps AddTorque and not the spring torque so increasing it would solve the problem. I'm sorry I have not been intelligent enough to try that before, but I think you downvoting this answer only makes people who have the same problem (which I have found in other threads without solution) harder to find a concise and real solution.

avatar image
0

Answer by GamerLordMat · Aug 19, 2021 at 02:38 AM

see my video: https://youtu.be/4FZNab_dTWQ Hello, you don't usually do that with a spring activated, bc it tries to counteract all forces (plus damping slows the motion down). A spring tries to reach the goal angle (default is zero), so any force/torque you apply will be counteracted if it moves the angle away from the target destination.

In most cases you want to use spring (defining an angle) or torque, not both (but it is compatible). currentTorque is the torque it uses to satisfy all constraints.If your max angular velocity is low (default 20) than even very high torque won't change your rotation much, thus the currentTorque to counteract it won't be high. try to use instead:

   HingeJoint joint = GetComponent<HingeJoint>();
  JointSpring spring = joint.spring;
  spring.spring = 60;
  spring.damper = 1.5f;
  joint.spring = spring;
  joint.useSpring = true;

and define the angle, so it will try to reach this angle automatically. Here my project where I created a PID-like controller with machine learning, and you clearly see how the spring tries to get to angle 0, even though my Machine Learning Agent tries to achieve another angle and applies torque, but has only 30 Torque, so the spring "wins". A PID Controller tries to minimize the error between the specified value and the current value and I think that spring is implemented in a similar fashion. see my video https://youtu.be/4FZNab_dTWQ

Comment
Add comment · Show 5 · 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 llermy · Aug 19, 2021 at 05:20 AM 0
Share

The HingeJoint.spring object you mention is actually the same as the spring option in the editor in HingeJoints. But I also checked to add the spring joint by script as you mention, so as to confirm whether it is a problem of the editor option, with:

 HingeJoint joint = GetComponent<HingeJoint>();
 JointSpring spring = joint.spring;
 spring.spring = 60;
 spring.damper = 1.5f;
 joint.spring = spring;
 joint.useSpring = true;

But it does not change anything. By the way, you need to set HingeJoint.useSpring to true if you want to add spring by script.

The problem is not with the damper. If the spring value is 0, the torque is added correctly with any damper value, it just rotates slower as expected due to the damping force. But if I set the spring value, the torque doesn't make any significant rotation even with very high torque values as parameter of`AddTorque` function.

avatar image GamerLordMat llermy · Aug 19, 2021 at 09:07 AM 0
Share

see my video https://youtu.be/4FZNab_dTWQ

like I said... it tries to reach the goal angle 0, so any force you apply will be counteracted. Here my project where I reacreated a PID controller with machine learning, and you clearly see how it tries get to 0, even though my Machine Learning Agent tries to achieve another angle and applies torque, but has only 30 Torque, so the spring "wins". A PID Controller tries to $$anonymous$$imize the error between the specified value and the current value, and I highly suspect that spring is implemented this way.

Either use spring (defining an angle) or torque, not both.

avatar image llermy GamerLordMat · Aug 19, 2021 at 09:14 AM 0
Share

Thanks for the video but it's private so I cannot see it :) I'm actually not talking about a torque of 30, even a torque of 100000 does not rotate the joint noticeably. However, I suppose you mean that HingeJoint.spring and AddTorque are not compatible and there is no solution.

Show more comments

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

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

Adding Torque to a Hinge Joint 1 Answer

Is there a 2d joint for a torsion (rotation) spring? 0 Answers

Physic Torque Hinge joint problem 0 Answers

How to rotate rigidbody relative to jointed other rigidbody? 2 Answers

How to find the point of contact with the function OnTriggerEnter??? 4 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