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 Bloodyem · Nov 02, 2013 at 06:25 PM · rotationrigidbodytorque

Rotate a rigid body while it's constrained.

I'm having an issue rotating a rigidbody. If I constrain it, it looks great, but I can't turn. If I don't constrain it, it falls right over. Is there a method I can use to keep it constrained, (so it won't fall over), and still be capable of rotating it's Y axis?

Thank you very much for your help. Below is the script. It's extremely basic at the moment, so I'm not sure how much help it'll be, but it might.

 var speed : float;
 var power : float;
 var evolution : int;
 var vert : float;
 var hori : float;
 
 function Start () {
 
 }
 
 function Update () {
 vert = Input.GetAxis("Vertical");
 hori = Input.GetAxis("Horizontal");
 
 if (vert > 0)
     {
         rigidbody.AddRelativeTorque(Vector3(speed + power, 0, 0), ForceMode.Force);
     }
 if (vert < 0)
     {
         rigidbody.AddRelativeTorque(Vector3(-(speed + power), 0, 0), ForceMode.Force);
     }
     
 if (hori > .9)
     {
         rigidbody.AddTorque(Vector3(0, 10, 0));
     }
 if (hori < -.9)
     {
         rigidbody.AddTorque(Vector3(0, -10, 0));
     }
 }
Comment
Add comment · Show 1
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 Tomer-Barkan · Nov 03, 2013 at 04:54 AM 0
Share

You can't use physics (`AddTorque()`) to rotate the rigidbody if it is constrained, that is exactly the point of this constraint...

On the other hand, you can rotate the GameObject directly using transform.Rotate() or, my personal favorite, just set transform.forward = whereIWantTheObjectToFace.normalized;

2 Replies

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

Answer by clunk47 · Nov 02, 2013 at 09:00 PM

Rigidbody.rotation

Transform.Rotate

Transform.localEulerAngles

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 Zaeran · Nov 02, 2013 at 06:31 PM

Only constrain the x and z axis for rotation. There should be checkboxes for this in the inspector for your rigidbody

Comment
Add comment · Show 4 · 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 Bloodyem · Nov 02, 2013 at 06:34 PM 0
Share

I can't do it that way. It needs to rotate on the X and Y axis. If I only constrain the Z axis, it falls right over.

avatar image Zaeran · Nov 02, 2013 at 07:03 PM 0
Share

Ahh, I see. Could you possibly constrain x until you need to rotate, then re-constrain after?

avatar image Bloodyem · Nov 02, 2013 at 07:14 PM 0
Share

No, tried that. It just fell over when I tried to turn.

Think of it like a tire. It needs to rotate on the X to move forward, and on the Y to turn. That's where I'm getting my issue, is that the tire itself won't stay up, due to gravity, but whenever I've tried something similar in the past, the constraints on the rigid body just kept it from falling over.

avatar image MattBradley · Nov 18, 2013 at 03:52 PM 0
Share

Did you get this fixed at all? I'm having a similar issue now when trying to rotate around the Z and move up/down in the Y.

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

18 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

Related Questions

torque speeding up when the game is unpaused 2 Answers

How to rotate rigidbody relative to jointed other rigidbody? 2 Answers

Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers

Without affecting Velocity, what is the best method to apply direction to an object moving with forces? 1 Answer

add force to rotation 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