0
\$\begingroup\$

Unity's default FPS Controller keep momentum after you let go of the keys. Once you are up to full speed with WASD and let go, it continues to move for a bit.

How do I stop this momentum? Immediately upon letting go of the keys, I want the character to stop.

I am looking into the script already, but I am new to Unity. If someone can point me to what I am looking for, please do!

P.S. It appears it may be due to a connection to GetAxis which has built in momentum. https://docs.unity3d.com/ScriptReference/Input.GetAxis.html

\$\endgroup\$
  • \$\begingroup\$ You may want to consider some sort of friction force that opposes the character on the ground (or air resistance if they are flying). If there is no force to stop the character, they will continue to move. If there is already an opposing force and they do slow down eventually, just move that number up to increase resistance. \$\endgroup\$ – n_plum Feb 8 '17 at 13:22
  • 1
    \$\begingroup\$ It might be Input.GetAxisRaw that I need: "Returns the value of the virtual axis identified by axisName with no smoothing filtering applied. The value will be in the range -1...1 for keyboard and joystick input. Since input is not smoothed, keyboard input will always be either -1, 0 or 1. This is useful if you want to do all smoothing of keyboard input processing yourself." \$\endgroup\$ – Xonatron Feb 8 '17 at 15:36
2
\$\begingroup\$

The answer is using Input.GetAxisRaw instead of Input.GetAxis:

"Returns the value of the virtual axis identified by axisName with no smoothing filtering applied. The value will be in the range -1...1 for keyboard and joystick input. Since input is not smoothed, keyboard input will always be either -1, 0 or 1. This is useful if you want to do all smoothing of keyboard input processing yourself." - https://docs.unity3d.com/ScriptReference/Input.GetAxisRaw.html

I tried it in my game demo and it worked. As soon as you let go of WASD the character stops, exactly as you would expect.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.