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. Dismiss Notice

Why does my character not stop moving immediately after I release the movement buttons?

Discussion in 'Input System' started by Hangjo, Jun 4, 2014.

Thread Status:
Not open for further replies.
  1. Hangjo

    Hangjo

    Joined:
    Apr 20, 2014
    Posts:
    20
    My character always slides across the screen and I can't figure it out. Any ideas?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Change the input manager settings for gravity, etc.

    --Eric
     
  3. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Are you using Input.GetAxis? It applies a little smoothing when using keyboard controls so that values don't change instantaneously. Try using Input.GetAxisRaw instead.
     
  4. Hangjo

    Hangjo

    Joined:
    Apr 20, 2014
    Posts:
    20
    I changed Input.GetAxis and there is still no difference, input manager didn't change anything either unless I did something wrong with it.
     
  5. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Are you moving by adding forces?
     
  6. Hangjo

    Hangjo

    Joined:
    Apr 20, 2014
    Posts:
    20
  7. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
  8. Brutang

    Brutang

    Joined:
    Nov 1, 2013
    Posts:
    23
    Here's my solution:

    Code (JavaScript):
    1.  
    2. var h:int; //reference variable for horizontal axis
    3.  
    4. function Update()
    5. {
    6.      if(Input.GetButton("Left")||Input.GetAxis("LThumbstick Left/Right")<0)
    7.           h=-1;
    8.      else if(Input.GetButton("Right")||Input.GetAxis("LThumbstick Left/Right")>0)
    9.           h=1;
    10.      else
    11.           h=0;
    12.  
    13.      if(h==0)
    14.           rigidbody2D.velocity=Vector2(0,rigidbody2D.velocity.y); //if you're not pushing left/right it will stop you on a dime without changing the Y velocity so you can still fall.
    15. }
     
  9. CamusQuin

    CamusQuin

    Joined:
    Apr 25, 2020
    Posts:
    1
    Thanks man.
     
  10. electromaster20000

    electromaster20000

    Joined:
    Aug 18, 2020
    Posts:
    2
    Thanks, this works wonders for my game :)
     
  11. Vedfjord

    Vedfjord

    Joined:
    Jul 7, 2015
    Posts:
    2
    9 years later, and this still saved my day. Thanks a bunch
     
  12. Vedfjord

    Vedfjord

    Joined:
    Jul 7, 2015
    Posts:
    2
    Also, if others are new to this, the gravity and sensitivity settings is not related to gravity in physics. (I first understood that when I read this)

    upload_2023-9-24_13-33-5.png
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,414
    Please stop necroing posts.
     
Thread Status:
Not open for further replies.