Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by S_Mario86 · Mar 15, 2016 at 04:09 PM · addforceangularvelocityaddrelativetorque

AddRelativeTorque and gameobject's angularVelocity

I've been experimenting around with some of the physics in Unity and something seems weird to me with the AddRelativeTorque function. I have the following code in order to slow and eventually stop a gameobject's spinning.

         if ( ship.angularVelocity != Vector3.zero )
         {
             ship.AddRelativeTorque( ship.angularVelocity * -1 );
         }

Elsewhere I have this line to apply a spin to it using input from a controller or keyboard.

     ship.AddRelativeTorque( Vector3.up * Input.GetAxis( "Rotate" ) / 2 );

I don't fully understand how the physics behind AddTorque work, but from what I understand, this should apply a force opposite to the current velocity, thus slowing down and stopping the object. It does work, but if I apply enough other forces on the object, then it'll start spinning uncontrollably.

I know how to achieve what I'm trying to do in a number of different ways that I know work. I just want to know what is happening and why it's happening. I assume it has something to do with how Unity handles forces and other physics, but I don't fully understand what's going on.

In case there's something in the rest of the code, here is the full set of functions. It happens most often when the explosion force is activated several times in a row, but the strange spinning will still occur even if I'm just navigating around the world and not colliding with anything.

     void moveShip ()
     {
         if ( !collided )
         {
             ship.AddRelativeForce( Vector3.forward * Input.GetAxis( "Vertical" ) );
 
             ship.AddRelativeForce( Vector3.right * Input.GetAxis( "Horizontal" ) );
 
             ship.AddRelativeForce( Vector3.up * -Input.GetAxis( "Up" ) );
 
             ship.AddRelativeTorque( Vector3.up * Input.GetAxis( "Rotate" ) / 2 );
         }
 
         if ( ship.velocity != Vector3.zero )
         {
             ship.AddRelativeForce( -ship.velocity.x / 2, - ship.velocity.y / 2, -ship.velocity.z / 2 );
         }
 
         if ( ship.angularVelocity != Vector3.zero )
         {
             ship.AddRelativeTorque( ship.angularVelocity * -1 );
         }
 
     }
 
     void OnCollision( Collision obj )
     {
         if ( obj.gameObject.CompareTag( "Cube" ) )
         {
             ship.AddExplosionForce( 1, obj.transform.position, 1 );
 
             collided = true;
         }
     }
 
     void OnCollisionExit( Collision obj )
     {
         if ( obj.gameObject.CompareTag( "Cube" ) )
         {
             collided = false;
         }
     }
 
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 Joaquito · Mar 14, 2017 at 09:36 AM

I've been struggling with the same, more exactly trying to stabilize a spaceship's spinning on X and Z, and yes, at some point you see it starts spinning uncontrollably as you say. I've come to the conclusion that AddRelativeTorque takes the values that you put, and makes "Relativeness calculations" instead of simply adding Torque to "Local X/Y/Z Axis". It's kinda hard to understand and explain, but the point is that AddRelativeTorque is not as good and as life-simplifying as it looks, but rather weird. I'd just use AddTorque and make any necessary calculations myself within code rather than using it.

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

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

50 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 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 avatar image avatar image avatar image avatar image

Related Questions

How control Rigidbody2d using GetAxis with AddForce and angularVelocity (2D) 1 Answer

How do I create Sling-Shot like propulsion? 1 Answer

How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer

Confused about addForce behavior on 3D objects w/ sub-objects in 2D movement 0 Answers

bullet wont move forward 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