Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Jean-Fabre · Aug 10, 2010 at 03:47 PM · rotationquaternionconfigurablejoint

configurable joint targetrotation: How to compute it

Hi Everyone,

I am having problems computing the targetrotation of a configurable joint.

START EDIT You can find the application resulting from this question here

http://www.fabrejean.net/projects/excavator

END EDIT

background: I am swapping the JointDriveMode from velocity to position drive when the targetAngularVelocity magnitude is 0. So I need to compute out of the blue the targetRotation of a joint. I do not know nor can maintain a variable holding this variable since it was driven using velocity and the joint unfortunatly can not be queried for this. Also, the joint is not configured in worldspace.

for convenience and to avoid misinterpretations, I have added the sources of this specific problem online and with a webplayer version:

http://www.fabrejean.net/projects/unity/velpos.html

I am using currently:

 GetComponent(ConfigurableJoint).targetRotation
 = Quaternion.Euler(joint.connectedBody.transform.localEulerAngles)

This is not working when the rigidbody implementing the joint is itself constraint by another configurable joint. Basically it doesn't work with a chain of joints. it jumps to weird angles instead. While this works very well when the rigidbody holding the joint is not attached to anything. I could be wrong in this assumption, but that's what I am experiencing so far.

So:

Is there actually a way to switch JointDriveMode from velocity to position and have the joint stay in its current position? Currently if you switch it jumps back to the default values.

Is there a proper way to find out about the targetRotation accuratly in all situations?

Thanks for your help. I can provide a small example if someone is interested to get a proper working case of this.

Jean,

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Jean-Fabre · Aug 12, 2010 at 08:04 AM

Ok, found the solution.

The solution that I implemented is to compute the position from the "parent" space which is the rigid body implementing the joint, then use lookRotation, the resulting quaternion is properly define in the local space.

pos = transform.InverseTransformPoint(joint.connectedBody.transform.position);
GetComponent(ConfigurableJoint).targetRotation = Quaternion.LookRotation(pos);

One could probably do that directly with rotation component, if there is a better way I am all hears.

Jean

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 Magnus Wolffelt · Aug 12, 2010 at 10:12 AM 0
Share

That's odd. Thanks for sharing.

avatar image Jean-Fabre · Aug 13, 2010 at 10:23 AM 0
Share

yes, also as I worked more with this script and other rigs, computing with the position has a flow when the connected body position doesn't change, it happens with some rigging strategies. So I am currently investigating how to compute the targetRotation based on the actuyl direction not the pos and provide a public switch so that the script is as generic and work in all cases as much as possible.

avatar image
2

Answer by mstevenson · Feb 15, 2013 at 07:03 AM

I've created a set of extension methods for computing a ConfigurableJoint's targetRotation from either a local or world rotation. The solution is not trivial, and all solutions I've found online have failed to take into account arbitrary "axis" and "secondary axis" values. With some careful quaternion math it's possible to transform a local or world space rotation into a joint space rotation while supporting variable joint axes.

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
1

Answer by Magnus Wolffelt · Aug 11, 2010 at 01:16 PM

Interesting question. The only thing that strikes me is that you shouldn't have to go via euler angles. Just set the target rotation to transform.localRotation.

Anyway, not sure if that solves the problem. Probably not.

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 Jean-Fabre · Aug 12, 2010 at 05:09 AM 0
Share

Hi, That's how I started originally but it doesn't give the wanted result neither unfortunately.

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

ConfigurableJoint - angular positions (rotation) problem 1 Answer

How to transmit the correct rotation (quaternion) to an configurable joint? 1 Answer

How to fix this strange child 3D rotation? 0 Answers

Using Configurable Joints to create Pinball Flippers? 3 Answers

transform.rotation vs Quaternion.Euler 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