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
0
Question by xavram · Feb 11 at 05:43 PM · rigidbodyaddtorque

Using AddTorque to rotate but can't stop it

New to unity, so this might be very simple (hopefully).

I'm using AddForce to move a body along, at a continuous speed, that's no issue...

rigidBody.AddForce(transform.forward Time.deltaTime forceApplied, ForceMode.VelocityChange);

Then I have simple code to turn the object, using AddTorque

     if (Input.GetKey(KeyCode.D))
     {
         rigidBody.AddTorque(transform.up  * forceApplied/5 * Time.deltaTime, ForceMode.VelocityChange);
     }

     if (Input.GetKey(KeyCode.A))
     {
         rigidBody.AddTorque(transform.up * -forceApplied/5 * Time.deltaTime, ForceMode.VelocityChange);
     }

but when I stop pressing the A or D keys, the object continuous to move around in a circle.

What I want is very basic "steering", so that if you hold down A/D, you turn in the appropriet direction but once you release the key, you resume straight line movement.

Note for this exercise, I'm not worries about Mass being involved (that's why I'm using Velocity Change).

Thanks for any advice!

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 BastianUrbach · Feb 14 at 09:58 AM

To stop an object from moving or rotating, you would have to apply a force or torque to it.

"A body continues in its state of rest, or in uniform motion in a straight line, unless acted upon by a force." - Isaac Newton

You'll have to decide if you want realistic, physically based movement or unrealistic, "snappy" controls. If you want realistic movement, you can set a higher drag and angular drag on the rigidbody. These will slow down the rigidbody in a manner that approximates air resistance. If the rigidbody lies on a surface, you can also increase its friction or that of the surface by assigning an appropriate Physics Material to the Collider. If you just want the object to move as you say without much regard for physical accuracy, you can set the velocity and angularVelocity of the rigidbody directly instead of applying forces and torques. To stop it, you just set them to zero.

Side note: Instead of multiplying by delta time manually, you can also use ForceMode.Acceleration. That still ignores mass but does the multiplication by Time.deltaTime for you.

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 xavram · Feb 14 at 03:49 PM

Thank you for the tips, particularly the part about Acceleration vs VelocityChange!

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

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

Issue with Rotation behaviour of PID Controller when rotating to look at mouse position 0 Answers

Using Torque to kill Angular Velocity 2 Answers

If a rigidbody is attached, should you always use AddTorque/AddRelative force for rotation/movement? 1 Answer

AddTorque Isn't Working? 1 Answer

How to move a rigidbody along a curve or spiral 0 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