• 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 Marcopolo1613 · Apr 26, 2014 at 08:35 PM · anglejointsconfigurable joint

How to control the angle of a joint using a variable

I want to use a variable to control the angle between two connected objects in unity, but I'm not sure what syntax to use for scripting the joint.

So I have a variable between 0 and 255, and I want the angle of a joint to match that number. How can I script the transform?

P.S. I'm pretty new to unity, and I'm using C# because I'm getting the angle data from a sensor attached to my computer.

Comment

People who like this

0 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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by MikeNewall · Apr 26, 2014 at 09:01 PM

Attach a script to the root joint and set its rotation by multiplying a vector by the input value. For example t$$anonymous$$s would rotate around the X axis the number of degrees specified by the variable:

 transform.rotation = Quaternion.Euler(Vector3.right * inputVariable);
Comment

People who like this

0 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 Owen-Reynolds · Apr 26, 2014 at 09:46 PM 0
Share

Quaternion.Euler( inputVariable, 0, 0); is the same thing, and I find it easier to read.

avatar image MikeNewall · Apr 27, 2014 at 12:35 AM 0
Share

I'm used to thinking in vectors :p But yeah that is easier to read. I suppose the benefit of using a vector like that is you can change the rotation axis on the fly.

avatar image

Answer by Marcopolo1613 · Apr 30, 2014 at 03:56 AM

Thank you all for your help, I was able to do what I wanted with a Hinge Joint, and t$$anonymous$$s code:

 JointSpring spr = $$anonymous$$ngeJoint.spring;
 
 spr.targetPosition = myInputData; // myInputData is the input from my sensor
 
 $$anonymous$$ngeJoint.spring = spr;

T$$anonymous$$s makes the joint move toward the angle value I am receiving from my sensor.

Comment

People who like this

0 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 off99555 · Oct 11, 2018 at 03:29 AM 0
Share

How do you stop the joint from bouncing back and forth when it reaches the angle you specify? I want to set the angle and prevent it from moving anymore.

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

23 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

Related Questions

How to set specific angle between 2 game objects in unity 0 Answers

How do I apply rotations to parent child using Rigidbody? 0 Answers

Components jittering - Configurable joints 0 Answers

Configurable Joint angular X limits are inverse of transform.rotation and Slerp drive rotates inversely for angular velocity 0 Answers

joint with two axis 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