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 /
  • Help Room /
avatar image
0
Question by Potatobob · May 04, 2016 at 06:17 AM · anglejointhingejointspringtargetrotation

How to get Target Position to follow another Hinge joint Angle?

Hi , in my project I have to make an hinge target position to be equal to the angle of another hinge.

Let me explain: I have two arms and I would like the second one to attempt to reach the same angle as the first one while using physics and collision. (This is why I use hinges).

The player can move the arm 1 which is not using the spring feature of the hinge (this arm move but doesn't react to physics as designed)

Then the second arm should respond by attempting to reach the angle of the (arm 1) hinge joint.

The expected result is that both arm have the same angle when it is possible (collisions might occur on arm 2 but spring will react with the target position)


So I am using the Target Position on arm 2 by copying the arm 1 Angle.

What I understand is that the "angle" variable of a hinge joint correspond in it's distance from his starting position BUT it doesn't give the good results.


So here is what I attempted to do in order to understand my problem:

  • Create 2 cubes

  • Add Rigidbody to both cubes.

  • Select cube 1 and freeze his rigidbody rotation and position.

  • Select cube 2 and add a hinge joint.

  • Set it up to rotate around the y axis so no gravity will affect it's position.

  • Set those values on the hinge joint from the inspector:


Use spring = true


Spring spring = 150


spring damper = 150


target position = 0


  • Attach a script to the cube with the hinge that will Print out the "Angle" variable from the hingejoint.

  • Launch the game and modify the target position at runtime while keeping an eye on the angle value.

While doing this I noticed that when entering 100 as target position the angle printed would be 98-100 as expected BUT when making the second change the result start breaking. When setting the target position to 0 the angle jumps from 100 to -76...

If anyone can help me to get the proper angle out of my joint I would really be happy.

Thank you very much for your help!

(This is the code to print the Hinge Angle)


 private HingeJoint myJoint;
 void Start(){myJoint = GetComponent<HingeJoint>();}
 void Update () {Debug.Log(myJoint.angle);}

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
0

Answer by robotloveskitty · Dec 27, 2016 at 02:44 AM

I am also getting crazy angle values from my hinge joint. Anytime I change the target velocity on the motor it seems to reset the angle to 0 at it's current rotation. Trying to work around that :|

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 StevenDelrue · Jan 19, 2018 at 09:30 PM

The target velocity needs to be a value between -180 & 180. If it goes under or above, it clamps to 0.

Quick fix:

     angleBeforeDrag = transform.rotation.eulerAngles.z;
     if (angleBeforeDrag < -180f) angleBeforeDrag += 360f;
     if (angleBeforeDrag > 180f) angleBeforeDrag -= 360f;

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

55 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

Related Questions

Is there any way to get a hinge joint to NOT let an object spring back to its original position? 2 Answers

Hinje joint doesn't let a skate move freely,Hinje joint doesn't let a car move freely 0 Answers

Is it possible make an inverse Hinge Joint? 0 Answers

How does hinge joint work? 0 Answers

Local Hinge Joint Angle? 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