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
0
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
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 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 this would rotate around the X axis the number of degrees specified by the variable:

 transform.rotation = Quaternion.Euler(Vector3.right * inputVariable);
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 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
0

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 this code:

 JointSpring spr = hingeJoint.spring;
 
 spr.targetPosition = myInputData; // myInputData is the input from my sensor
 
 hingeJoint.spring = spr;

This makes the joint move toward the angle value I am receiving from my sensor.

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

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

joint with two axis 1 Answer

How to detect when joint reaches its limits? 0 Answers

Joint system scale problems 2 Answers

How angle limit in hingle joint 2d work ? 0 Answers

How target rotation and target angular velocity work in configurable joint ? 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