Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to remove inertia from objects?

Discussion in 'Physics' started by Exarpo, Dec 26, 2019.

  1. Exarpo

    Exarpo

    Joined:
    Nov 25, 2019
    Posts:
    51
    I'm quite new to unity and programing and I have run into some issues with my game, im using AddForce on my player to move but after pressing for example "a" to move to the left iwant it to just move a little bit and then stop, the problem is that it keeps moving for a bit until it stops, my questions is how do I remove the inertia so that it only moves when I'm holding the key down and then immediately stops when i release it.
     
  2. DarkOmen20

    DarkOmen20

    Joined:
    Dec 31, 2019
    Posts:
    5
    I believe if you add something like the following you should get your desired result:

    Code (CSharp):
    1. If (Input.GetKey(KeyCode.a) || Input.GetKey(KeyCode.w)) //continue for all movement keys
    2. {
    3.     //move logic here
    4. }
    I’m quite new myself so apologies if I’ve made a mistake, but I just did this literally last night and it worked great for me!
     
  3. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,690
    Increase the rigidbody's drag. This will make it lose linear velocity faster over time, eventually coming to a stop.

    Increasing the angular drag does the same, but for angular velocity.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    Set the rigidbody velocity directly, don't use forces to modify the velocity indirectly. You can then stop it immediately by setting the velocity to zero. You can control both the linear and angular velocities like this.