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 kewlhead · Feb 07, 2012 at 04:35 AM · rotationjoystickjointhingeps3

Directly Rotate a Hinge?

Hey guys, I've got most of this game worked out, and it's actually functioning great, but I'm trying to add another control scheme and I can't seem to get it working... In the game, you're arms are attached to the body via hinge joint, and you press Left/Right to rotate them around using this type of action:

 if(Input.GetKey("d")){
 
     hingeJoint.motor.force = force;
     hingeJoint.motor.targetVelocity = 350;
     hingeJoint.motor.freeSpin = false;
     
 }

Now, I also set this up for use with my PS3 controller, as such:

     if(Input.GetAxis("LHorz")){
     hingeJoint.motor.force = force;
     hingeJoint.motor.targetVelocity = velo*rotspeed;
     hingeJoint.motor.freeSpin = false;
     

}

What I want to be able to do, is instead of just adding to the motor's velocity, I want to be able to rotate the arm to point exactly where the analog stick is pointing. The code that I can use that works fine for a regular object is this:

 var axisHorizontal = Input.GetAxis("Horizontal");
 var axisVertical = Input.GetAxis("Vertical");

 transform.localRotation = Quaternion.Euler((Mathf.Atan2(axisHorizontal, axisVertical) * Mathf.Rad2Deg), 0.0 , 0.0);

The problem is, is when you apply that code to the arms, which again are attached to the body by a hinge joint, the whole character just goes absolutely haywire...

Here's a pic so you can get the idea of what motion I'm trying to get at:

alt text

Thanks so much for any help!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KalebGraceTwistory · Feb 03, 2015 at 12:31 AM

Try this:

 float angle = 45f;
 JointLimits jl = new JointLimits();
 jl.min = angle;
 jl.max = angle;
 hingeJoint.limits = jl;

It seems to work great for me. Note: If you're actually using the limits for the standard purpose, you'll have to cache off the original JointLimits struct and reapply it later.

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 gkillz · Nov 03, 2015 at 09:48 AM 0
Share

Will this solution working fine if the body is continuously in contact with other non kinematic rigidbodies which are resting on this joint. and u want to slowly rotate the joint to let them fall ...

i meam will there be any issues in their force exchange?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a rope 0 Answers

advanced problem for me regarding transfering rotation from the gizmo to the object 0 Answers

Rotate An Object Toward The Direction The Joystick Is Pressed 3 Answers

stay the rotation in character 1 Answer

Making my Game Object face according to direction of mobile joystick 2 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