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 /
This question was closed May 28, 2014 at 12:23 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
10
Question by csgeorge · Sep 25, 2013 at 09:03 PM · javascriptmovementrigidbody

Remove Force from Moving Object

I have a rolling ball that the player can move around, which I'm doing using rigidbody.AddForce. I want to include a button (Left Shift, in my current code) that stops the ball completely, but am running into an issue. The ball stops still the moment the button is pressed, but afterward will continue rolling just as it was before. I've tried adjusting the ball's physics material friction and the AddForce Force Mode, neither seem to make any difference.

Can anyone help me to get the ball to halt completely, and not move again until the player's next input?

 function FixedUpdate ()
 {
     if(Input.GetKeyDown(KeyCode.LeftShift))
         rigidbody.velocity = Vector3.zero; 
     
     if(Input.GetKey("up"))
         rigidbody.AddForce(0,0,speed); 
         
     if(Input.GetKey("down"))
         rigidbody.AddForce(0,0,-speed); 
     
     if(Input.GetKey("right"))
         rigidbody.AddForce(speed,0,0);
         
     if(Input.GetKey("left"))
         rigidbody.AddForce(-speed,0,0);
 }
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

  • Sort: 
avatar image
29
Best Answer

Answer by robertbu · Sep 26, 2013 at 01:21 AM

You also need to set the angularVelocity to zero:

 if(Input.GetKeyDown(KeyCode.LeftShift)) {
    rigidbody.velocity = Vector3.zero;
    rigidbody.angularVelocity = Vector3.zero; 
    }
Comment
Add comment · Show 9 · 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 csgeorge · Sep 26, 2013 at 05:31 AM 0
Share

Worked like a charm, thanks!

avatar image WSllc · May 28, 2014 at 12:19 AM 0
Share

I also had this problem and overlooked the angular velocity. Thanks robertbu! You've helped me too!

avatar image tapticc · Jun 16, 2014 at 06:59 PM 0
Share

Sorted my random sliding of my car as well, cheers!

avatar image zark · Feb 01, 2015 at 12:55 AM 0
Share

rigidbody.angularVelocity = Vector3.zero; > this does not work though i used rigidbody.angularVelocity = 0f;

avatar image Zoelovezle zark · Dec 21, 2015 at 10:10 AM 0
Share

It might be because of update. Since csgeorge said it worked :)

avatar image VaskeDaGame · Jun 05, 2018 at 09:54 AM 0
Share

can you help me as well? i want my player to stop the forces when he moves right or left. but if hes in the air that makes him float. i want to only stop his velocity on X axis. so that it stays the same on the Y. i tried putting RigidBody.Velocyty.x but it gives me an error. is there a way?

Show more comments

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Move RigidBody character relative to camera. 2 Answers

Rigidbody.MovePosition doesn't move reliably? 1 Answer

Weird Movement 1 Answer

help fix my script 3 Answers

How to make an object wait until it finishes moving? 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