Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Lambastard · Jan 08, 2014 at 07:11 PM · physicsrigidbodyangularvelocityaddtorqueaddrelativetorque

Using Torque to kill Angular Velocity

I'm trying to write a method that adds a limited amount of torque to a rigidbody in order to slow its rotation. I tried to do it in a way that, apart from limiting the actual force to a lower value, basically amounted to the following:

rigidbody.AddRelativeTorque(-rigidbody.angularVelocity);

It was meant to be applied over multiple FixedUpdate() cycles until the angular velocity was completely cancelled. But of course, nothing goes as planned, and instead I just have rigidbodies rotating around their z axes a lot. There is no drag and no other forces affecting it, mind you.

Now, I tried converting the angularVelocity from radians to degrees, I tried AddRelativeTorque and AddTorque, and I also tried plenty of modifications to the exact amount of force applied - to no avail.

My instincts tell me that getting the angularVelocity vector, multiplying it with (-1) and applying that as force should slow rotation and cancel it eventually (the time needed depending on the objects mass)...but it doesn't work that way.

Any ideas, gentlemen?

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
1
Best Answer

Answer by robertbu · Jan 08, 2014 at 07:19 PM

Untested, but I'm pretty sure this will work. It should be done in FixedUpdate(), and the slowdown will not be linear. You may need to fiddle with the constant.

 rigidbody.angularVelocity *= 0.985;

Depending on how you want to motion to slow, you can use Lerp() or MoveTowards, or others to scale the components of angularVelocity to 0 over time. Based on your question, I'm think you already realize you could play with the 'angularDrag' setting...upping it to get the object to slow then returning it to some value after the angularVelocity falls below some threshold.

Comment
Add comment · Show 3 · 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 Lambastard · Jan 08, 2014 at 07:24 PM 0
Share

Thanks, but that's really not quite what I'm looking for. The possibility of "Faking" it by directly manipulating the angularVelocity or temporarily adding angularDrag is obviously handy, and I'll resort to it if nothing else works out, but I'd really prefer a torque-based solution :)

avatar image robertbu · Jan 08, 2014 at 07:27 PM 0
Share

I just ran a quick test, and adding torque in the opposite of Rigidbody.angularVelocity() worked fine to slow/stop an object.

 #pragma strict
 
 function Start() {
     rigidbody.AddTorque(Random.insideUnitSphere * 200.0);
 
 }
  
 function FixedUpdate() {
     rigidbody.AddTorque(-rigidbody.angularVelocity * 0.1);
 }
avatar image Lambastard · Jan 08, 2014 at 07:32 PM 0
Share

Then I guess I really must be doing something else wrong. I'll have to do more testing. Thanks for confir$$anonymous$$g this!

avatar image
1

Answer by deneb3525 · May 06, 2019 at 02:33 AM

 Vector3 rotation = transform.InverseTransformDirection(rb.angularVelocity);
 
  if (rotation.y <= .1 && rotation.y >= -0.1)
             {
                 rotation.y = 0;
                 Debug.Log("cancel y");
             }
 else if (rotation.y > .1)
             {
                 rb.AddRelativeTorque(Vector3.up * yaw * -1);
             }
 else if (rotation.y < -0.1)
             {
                 rb.AddRelativeTorque(Vector3.up * yaw);
             }
 rb.angularVelocity = transform.TransformVector(rotation);



I know this is a fairly old question, but it took me a bit to solve a similar question. I cut the sections for X and Z, but they work the same as Y. This code was part of a greater fragment that allowed me to selectively damped various axis of a spaceships rotation. The "if (rotation.y <= .1 && rotation.y >= -0.1)" section is because this code would otherwise vibrate as the thrust would push rotation from one direction to the other every frame.

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 Lambastard · May 07, 2019 at 07:01 PM 0
Share

Hey, it's very late indeed and I've since solved the problem in various ways, but your answer is still much appreciated. Thanks!

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

20 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

Related Questions

AddRelativeTorque results in incorrect angular acceleration (Maybe centrifugal force affects) 0 Answers

rigid body Clone Instance not behaving like original 1 Answer

How to rotate with a Pid controller 0 Answers

AddTorque is spinning faster in one direction than the other.. 1 Answer

Restricting angularVelocity on one particular direction 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